Last active
August 29, 2015 14:21
-
-
Save masciugo/6c15eb5c59c5169957d1 to your computer and use it in GitHub Desktop.
Replace div with CSS only. JS Bin// source http://jsbin.com/nazase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
.switch { | |
position: relative; | |
} | |
.switch:hover .replace { | |
opacity: 1; | |
} | |
.switch .replace { | |
position: absolute; | |
top: 0; | |
height: 100%; | |
width: 100%; | |
opacity: 0; | |
transition: all 0.4s ease; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="switch"> | |
<img src="http://placehold.it/300&text=hover to change"/> | |
<div class="replace"> | |
<img src="http://placehold.it/300/bbbbb&text=covered!"/> | |
</div> | |
</div> | |
<script id="jsbin-source-css" type="text/css">.switch { | |
position: relative; | |
&:hover .replace { | |
opacity: 1; | |
} | |
.replace { | |
// a background may be necessary in case of different div size | |
// background: #18BC9C; | |
position: absolute; | |
top: 0; | |
height: 100%; | |
width: 100%; | |
opacity: 0; | |
transition: all 0.4s ease; | |
} | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.switch { | |
position: relative; | |
} | |
.switch:hover .replace { | |
opacity: 1; | |
} | |
.switch .replace { | |
position: absolute; | |
top: 0; | |
height: 100%; | |
width: 100%; | |
opacity: 0; | |
transition: all 0.4s ease; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment