I tried to make a grid like design, I want to show a overlay on hover to each div.
The overlay div has two button which should be placed in center.
i tried the below code i believe the logic is correct but the position of the button and overlay are not placing at the center of the image div.
Image Without overlay
On hover with 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 are changeable so fixed padding to center button may won't help here i think. Can anyone help me on positioning the overlay?
Changed a few things with the positions and also gave a height to the li element cause the img was bigger..
http://jsfiddle.net/4CqNK/8/
.image{
width:100px;
height:100px;
}
.overlay{
width:100%;
height:100%;
display:none;
position:absolute;
top:0px;
left:0px;
}
.overlay div {
position:relative;
display:inline-block;
top:50%;
margin:-50% 5px 0 0;
}
ul { list-style: none; width: 100%; }
ul li { position:relative;display:inline-block; width:150px;height:150px;}
li:hover .overlay {
display:block;
background-color:black;
opacity:0.75;
}
.bt1 {
background-color:orange;
width:50px;
height:50px;
}
.bt2 {
background-color:green;
width:50px;
height:50px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With