I tried to create a grid similar to the design, I want to show a hover overlay for each div.
The overlay div has two buttons that should be placed in the center.
I tried the code below. I believe that the logic is correct, but the position of the button and overlay does not fit in the center of the image.
No overlay image

Hover overlay

Html
<ul>
<li>
<div class="image"><img src="http://i.stack.imgur.com/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="http://i.stack.imgur.com/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="http://i.stack.imgur.com/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="http://i.stack.imgur.com/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
</ul>
CSS
.image{
width:100px;
height:100px;
}
.overlay{
width:100px;
height:100px;
display:none;
}
ul { list-style: none; width: 100%; }
ul li { display:inline-block; width:150px;}
.image:hover +.overlay {
display:block;
background-color:black;
top:0;
opacity:0.75;
}
.bt1 {
background-color:orange;
position:absolute;
width:50px;
height:50px;
margin:0 0 0 5%;
}
.bt2 {
background-color:green;
position:absolute;
width:50px;
height:50px;
margin:0 5% 0 0;
}
JSfiddle . Image size is variable, so a fixed pad to the center button may not help here, I think. Can someone help me with the placement of the overlay?
source
share