【问题标题】:My code works when hovering in but not when hovering out我的代码在悬停时有效,但在悬停时无效
【发布时间】:2022-02-14 06:55:55
【问题描述】:
Alright, so when I use this code and hover over the object, the transition works. But if I take my mouse OFF of the object, the transition doesn't happen. I've seen other posts talk about this but the solutions don't work.

这是我的 CSS 代码:

.square{
margin-top: 20px;
  height: 100px;
  width: 400px;
  border-radius: 20px;
  background:#3d3434;
  outline: none;
  transition: 0.25s;
}

.square:hover{
    outline: 3px solid #21ff46;
}

另外,我对编码和 CSS 还比较陌生。

【问题讨论】:

标签: html css


【解决方案1】:

您的代码可以正常工作。在 mouseleave 上看不到动画的原因是,hover 伪状态结束后,根本没有轮廓,浏览器不知道他必须将轮廓缩小到什么位置。它也不知道在收缩时应该保留什么颜色,没有悬停状态就没有定义颜色。

因此,解决方案是将此行添加到您的 .square 中

outline: 0 solid #21ff46;

其余的保持原样,你的问题就解决了。

【讨论】:

  • 谢谢,但过渡确实很不稳定。我现在该如何解决?
  • 只玩过渡持续时间的数字,0.25 可能太低了,当然这里也不是这样,但是尝试使用 .square { will-change: outline;如果这提高了平滑度,则意味着您的 PC 不够强大,无法在常规模式下处理该转换,它会挂起
  • 我尝试将其增加到 0.5 秒。它仍然很波涛汹涌
猜你喜欢
  • 2017-10-25
  • 2021-11-12
  • 1970-01-01
  • 2021-09-19
  • 1970-01-01
  • 1970-01-01
  • 2016-04-11
  • 2016-06-09
  • 1970-01-01
相关资源
最近更新 更多