val*_*als 14
你可以使用2个伪元素来做到这一点
CSS
.test
{
width: 400px;
height: 150px;
position: relative;
border: 1px solid green;
}
.test:before, .test:after {
content: "";
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
opacity: 1;
}
.test:before {
background-color: red;
z-index: 1;
transition: opacity 1s;
}
.test:after {
background-color: green;
}
.test:hover:before {
opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)
(悬停过渡)
为了能够看到div内容,伪元素需要在负z-index中:
看起来IE不会触发这个悬停
.test:hover:before {
opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)
但会触发这一个
.test:hover {
}
.test:hover:before {
opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)
(如同SILLY似乎)