I want to create the following hover effect: with hover
one div (.left)
should expand to full width and cover another div (.right)
.
This is what I have done so far: https://jsfiddle.net/Kubismus/tcm8nzu2/4/
$(".container").css({'height':($("img").height()+'px')});
.container { width: 100%; } .left { width: 67%; height: 100%; background: blue; float: left; } .right { width: 33%; height: 100%; float: right; z-index: -1; } img { max-width: 100%; height: auto; margin: 0; } .container:hover .left { width: 100%; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="left"> </div> <div class="right"> <img src="https://res.cloudinary.com/ddofbxz8d/image/upload/v1548087392/ka6fgbjakjeskramtkew.jpg"> </div> </div>
Explanation / Requirements:
The image has a 1: 1 aspect ratio. The height of the div .container
should determine the height of the image, which, in turn, should be 33% wide of the div .container.
Problems
Why does the image move down, although its z-index
set to -1
?
I tried several different approaches that I found on the Internet, but they do not work in my case.
For example, I do not want to set the position of the div .right
to position: absolute
, because I ignore the filling of the div .container
.
How can I solve this problem?