我已经通过单独指定属性进行了尝试,它可以工作,也许all 关键字失败了?
div:hover {
background-color: blue;
border-color: black;
-webkit-transition: background-color 0.5s ease, border-color 0.5s ease;
-moz-transition: background-color 0.5s ease, border-color 0.5s ease;
/* please note that transitions are not supported in IE 9 and there is no -ms prefix */
transition: background-color 0.5s ease, border-color 0.5s ease;
}
jsFiddle
更新:我想我明白你的问题了。您希望过渡在取消悬停时反转。在这种情况下,您还需要非悬停元素上的转换属性(没有:hover 的元素):
div {
width: 10rem;
height: 10rem;
background-color: purple;
border: thick solid orange;
-webkit-transition: background-color 0.5s ease, border-color 0.5s ease;
-moz-transition: background-color 0.5s ease, border-color 0.5s ease;
/* please note that transitions are not supported in IE 9 and there is no -ms prefix */
transition: background-color 0.5s ease, border-color 0.5s ease;
}
jsFiddle