Skip to content

Instantly share code, notes, and snippets.

@masciugo
Last active August 29, 2015 14:21
Show Gist options
  • Save masciugo/6c15eb5c59c5169957d1 to your computer and use it in GitHub Desktop.
Save masciugo/6c15eb5c59c5169957d1 to your computer and use it in GitHub Desktop.
Replace div with CSS only. JS Bin// source http://jsbin.com/nazase
<!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>
.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