I attempted to create a grid-like design where each div would display an overlay on hover.
The overlay div includes two buttons that should be centered.
Although I believe the logic of my code is correct, the position of the buttons and overlay is not centered on the image div as intended.
Image Display Without Overlay
Image Display On Hover With Overlay
Html Code
<ul>
<li>
<div class="image"><img src="https://i.sstatic.net/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="https://i.sstatic.net/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="https://i.sstatic.net/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
<li>
<div class="image"><img src="https://i.sstatic.net/rOVDt.jpg"/></div>
<div class="overlay"><div class="bt1"></div><div class="bt2"></div></div>
</li>
</ul>
CSS Code
.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 . Since the image sizes are changeable, fixed padding to center the buttons may not be a viable solution. Can anyone suggest a method for properly positioning the overlay?