You can do this using 2 pseudo elements
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; }
(transition to transition)
To be able to see the contents of a div, pseudo-elements must be in a negative z-index:
looks like IE will not run this hang
.test:hover:before { opacity: 0; }
but will run this
.test:hover { } .test:hover:before { opacity: 0; }
(As SILLY seems)
script for IE10
source share