不透明度转换不在两个方向上

时间:2015-07-14 21:20:40

标签: css css3 css-transitions opacity

我希望在进入时离开变暗状态时会转换,但只有在离开时才会转换。如何在进入时进行过渡?我也试过了ease-inease-out,但这些似乎没有什么区别。

.is-dimmed-unless-active:not(:active):not(:focus):not(:hover) {
    opacity: .5;
    transition: opacity .5s ease-in-out;
}

问题http://codepen.io/ryanve/pen/doKdgW

的实例

2 个答案:

答案 0 :(得分:3)

因为您需要在transition上定义.card

.card {
  transition: opacity .5s ease-in-out;
}

取而代之的是:

.is-dimmed-unless-active:not(:active):not(:focus):not(:hover) {
  transition: opacity .5s ease-in-out;
}

答案 1 :(得分:0)

将你改为css:

.is-dimmed-unless-active {
  transition: opacity .5s ease-in-out;
  opacity: 1;
}
.is-dimmed-unless-active:hover {
    opacity: .5;
}

.card {
  width: 60%;
  margin: 1em auto;
  padding: 1em;
  color: crimson;
  border: 3px dotted crimson;
}

body {
  font-family: sans-serif;
  background: white;
}