【问题标题】:Is it bad practice to set the transition property directly inside a pseudo class?直接在伪类中设置转换属性是不好的做法吗?
【发布时间】:2017-06-01 12:11:22
【问题描述】:

最佳做法是什么?为什么?这两种情况有区别吗?

1.

a {
    transition: color 325ms;
}

a:hover {
    color: red;
}

2.

a:hover {
    transition: color 325ms;
    color: red;
}

【问题讨论】:

    标签: css hover transition


    【解决方案1】:

    这不是一个坏习惯,这取决于。如果您将transition 放在伪class 中,则只有当您将鼠标放在元素上时才会发生转换,而如果您将transition 放在基本选择器本身上,它将在元素上设置动画鼠标悬停。

    Demo(仅当您在悬停时声明 transition

    对比

    Demo 2transition on mouseover + mouseout)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      相关资源
      最近更新 更多