I am trying to create a responsive grid of images (with descriptions) that when moused over will have a color overlay (just the image and not the text). Because of the responsive heights of the images, I am having an issue where the overlay covers everything and not just the image.
Any way I can fix this?
I've recreated the issue here for easier understanding: http://jsfiddle.net/r8rFc/
Here is my HTML:
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-3 project">
<a href="#">
<div>
<img src="http://placehold.it/500x500" class="img-responsive"/>
<div class="fa fa-plus project-overlay"></div>
</div>
<div style="text-align:center;">
<h3>Project name</h3>
<p>Image description</p>
</div>
</a>
</div>
</div>
And my CSS:
.project-overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(41,128,185,0.9);
color: #fff;
padding: 50%;
}
Thanks in advance!
Image Overlay: Image overlay generally refers to the image being a background image and inserting texts, and links inside of that image. It can be done using the 'card-img-overlay' property that is present in bootstrap. Also, we can do it with normal CSS along with a bootstrap theme.
Responsive images Images in Bootstrap are made responsive with . img-fluid . max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element.
To make an image responsive, you need to give a new value to its width property. Then the height of the image will adjust itself automatically. The important thing to know is that you should always use relative units for the width property like percentage, rather than absolute ones like pixels.
Add a class to the containing div, then set the following css on it:
.img-overlay {
position: relative;
max-width: 500px; //whatever your max-width should be
}
position: relative
is required on a parent element of children with position: absolute
for the children to be positioned in relation to that parent.
DEMO
When you specify position:absolute it positions itself to the next-highest element with position:relative. In this case, that's the .project div.
If you give the image's immediate parent div a style of position:relative, the overlay will key to that instead of the div which includes the text. For example: http://jsfiddle.net/7gYUU/1/
<div class="parent">
<img src="http://placehold.it/500x500" class="img-responsive"/>
<div class="fa fa-plus project-overlay"></div>
</div>
.parent {
position: relative;
}
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