This question already has answers here:
Bootstrap 3 CSS image caption overlay
(5 answers)
Closed 7 years ago.
I am trying to display overlay text on the Image using Bootstrap. I refereed the Stack Overflow Question and Answer. But Overlay is not fit into Image. I don't know What I have missed in that Answer
What I have tried Fiddle Here
Thank You
HTML
<div class="container">
<div id="DivOurProducts" class="row">
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/1">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/2">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/3">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/4">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
</div>
</div>
CSS
.fixOverlayDiv{
width:100%;
padding:0px;
}
.OverlayText{
background-color: #000;
bottom: 0;
color: #fff;
left: 0;
opacity: 0.5;
position: absolute;
width: 100%;
}
I found an Answer. I have missed Position = "relative" for Parent Div
CSS
In fixOverlayDiv class added Position = "relative"
.fixOverlayDiv{
position: relative;
width:100%;
padding:0px;
}
Updated Fiddle Here
Do you want to change the css class to .OverlayText{
background-color: #000;
bottom: 20%;
color: #fff;
left: 25%;
opacity: 0.5;
position: absolute;
width: 50%;
}
Related
Want to keep the image and div below at the same width.
Works fine until I get to around 545px to 575px window size. The .header changes width proportion only at col-md-12. Is there a way to keep the same aspect ratio?
SCREENSHOT
CODEPEN
HTML
<div class="container">
<div class="row">
<div class="first-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="second-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="third-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<!--END ROW-->
</div>
<!--END CONTAINER-->
</div>
CSS
.first-column{background-color: #c0c0c0}
.second-column{background-color: #808080}
.third-column{background-color: #778899}
.header{
background-color:rgba(45,44,89,0.7);
width: 100%;
color: #ffffff;
position: relative;
bottom: 40px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
}
The bootstrap .img-responsive class has a max-width:100%; but it doesn't set the width.
So add a width to the class.
.img-responsive {
width: 100%;
}
https://codepen.io/rickydam/pen/XarXYX
I have searched through almost every question asked about spacing between bootstrap columns but nothing seems to work. I'm thinking it could be a simple rookie mistake with the way I have structured my html/css but I can't seem to figure it out.
I've worked with bootstrap many times before but using a theme, this is my first time however only using a simple bootstrap navbar template with nothing else inside.
.img-container{
position: relative;
display: inline-block;
}
.img-container .overlay{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.1);
}
.img-container:hover .overlay{
display: block;
background-color: rgba(0,0,0,0.6);
}
.img-container .overlay .services-caption{
color: #fff;
font-size: 100px;
position: absolute;
top: 25%;
left: 20%;
}
<!--Services-->
<section class="services">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="img-container">
<img src="images/services/shop.jpg" alt="...">
<div class="overlay">
<span class="services-caption">Shop</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="img-container">
<img src="images/services/shop.jpg" alt="...">
<div class="overlay">
<span class="services-caption">Shop</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="img-container">
<img src="images/services/shop.jpg" alt="...">
<div class="overlay">
<span class="services-caption">Shop</span>
</div>
</div>
</div>
</div>
</div>
</section>
Add bootstrap col-md-offset-* class to achieve spacing between columns.
<div class="col-md-4 col-md-offset-1">
The above code will create a gap of 1 column size.
You can try padding, put test class on each <div class="col-md-4 test">
<style>
.test {
padding-bottom: 10px;
}
</style>
<div class="col-md-4 test">
<div class="img-container">
<img src="images/services/shop.jpg" alt="...">
<div class="overlay">
<span class="services-caption">Shop</span>
</div>
</div>
</div>
You can add a class called img-responsive. It will make the image responsively.
<div class="col-md-4">
<div class="img-container">
<img src="images/services/shop.jpg" class="img-responsive" alt="...">
<div class="overlay">
<span class="services-caption">Shop</span>
</div>
</div>
</div>
I am newbie in bootstrap and I have one problem.
<div class="container">
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
</div>
.box {
background-color: red;
height: 60px;
}
.hover {
position: absolute;
top: 0;
background: none repeat scroll 0% 0% rgba(20, 245, 43, 0.5);
width: 100%;
}
FIDDLE: https://jsfiddle.net/ocqpsvvc
Why if I use "width: 100%" for div.hover then background is outside of tag a? Background for div.box is ok.
I don't want use width with pixels or modify % because I would have modify this for all responsive layouts.
You are not taking into account the 15px bootstrap default padding.
add width: calc(100% - 30px); to make up for the padding. the calc is saying, make the width 100% minus 30px for the 15px right and 15px left. this will solve your issue.
see fiddle: https://jsfiddle.net/DIRTY_SMITH/ocqpsvvc/5/
Your problem is with the bootstrap "col" elements.
By default, these have padding on them, you will need to remove the padding.
E.G.
<div class="col-md-4 col-sm-6 col-xs-6" style="padding:0;">
EDIT:
Or add another class to the element so that css can remove the padding which will be cleaner.
E.G.
<div class="col-md-4 col-sm-6 col-xs-6 removePad">
.removePad{padding:0;}
I want to create equal padding with all div under the .slideshow div. The problem is the last div right padding.
Now looks like this:
I want this, just with equal padding / space between divs and equal img heights:
The code:
HTML:
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="product-container">
<div class="slideshow">
<p>Test message, Test message</p>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
</div>
</div>
</div>
</div>
CSS:
#import url('http://getbootstrap.com/dist/css/bootstrap.css');
.product-container{
padding: 0px 9%;
}
.slideshow{
background-color: #efeff1;
border: 1px solid #c5c5c7;
overflow: hidden;
}
.product-container img{
width:100%;
}
.col-lg-3{
padding-right:12px;
padding-left:0px;
}
Fiddle:
Fiddle
Just wrap all your image containing divs in additional .row:
<div class="row">
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
</div>
And remove unnecessary styling:
.col-lg-3{
padding-right:12px;
padding-left:0px;
}
Also, you don't need to repeat responsive classes for all devices:
<div class="col-sm-3 col-md-3 col-lg-3"></div>
Can be written:
<div class="col-sm-3"></div>
Updated fiddle
Is this what you're trying to acheive?
.product-container {
padding: 0 2px 6px 2px;
overflow: hidden;
}
.slideshow {
background-color: #efeff1;
border: 1px solid #c5c5c7;
padding-left: 20px;
}
.product-container img {
width: 100%;
}
.product-container .pads {
padding: 0px 3px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="col-lg-12">
<div class="product-container">
<div class="row">
<div class="slideshow">
<p>Test message, Test message</p>
</div>
<div class="col-sm-3 col-md-3 col-lg-3 pads">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3 pads">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3 pads">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
<div class="col-sm-3 col-md-3 col-lg-3 pads">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
</div>
</div>
</div>
</div>
I used the last-child selector. "Bla" is a class I added to the divs in question
.bla:last-child{
padding-right:0px ;
}
Had some issues with the height but used display: flex; to deal with that.
This wont work well in older browsers
http://jsfiddle.net/52VtD/12065/
If the right padding is removed it will have the result you are looking for.
http://jsfiddle.net/0rm0h547/light/
http://jsfiddle.net/0rm0h547/show/
css
.continuous {
padding-right: 0px;
}
html
..
<div class="col-sm-3 col-md-3 col-lg-3 continuous">
<img src="http://www.pacinno.eu/wp-content/uploads/2014/05/placeholder-Copy-4.png" alt="s">
</div>
..
Add an extra css class that removes padding-right.
You can give padding-right:0px; and you will get wat you want.
http://jsfiddle.net/52VtD/12070/
.col-lg-3{
padding-right:0px;
padding-left:0px;
}
Try:
remove
.col-lg-3{
padding-left:12px;
padding-right:0px;
}
add
.product-container .col-lg-3
{
padding-left:0px;
padding-right:0px;
}
I'm trying to make a grid layout with images inside, The images aren't always the same size, Some of them seem to make the layout of the grid slightly smaller and i can't figure out a way to get them all the same size.
Here's the HTML.
<div class="col-xs-12">
<div class="row">
<h2>Handheld Consoles</h2>
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<a href="#">
<div class="tile purple text-center">
<h3 class="title">Nintendo 3DS</h3>
<div class="col-xs-12"><img class="img-responsive" style="max-height:128px; max-width:128px" src="../images/3ds.png" /></div>
</div>
</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<a href="#">
<div class="tile red text-center">
<h3 class="title">Nintendo GBA</h3>
<div class="col-xs-12"><img class="img-responsive" style="max-height:128px; max-width:128px" src="../images/gba.png" /></div>
</div>
</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<a href="#">
<div class="tile orange text-center">
<h3 class="title">Nintendo 64</h3>
<div class="col-xs-12"><img class="img-responsive" style="max-height:128px; max-width:128px" src="../images/n64.png" /></div>
</div>
</a>
</div>
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<a href="#">
<div class="tile green text-center">
<h3 class="title">Sony PSP</h3>
<div class="col-xs-12"><img class="img-responsive" style="max-height:128px; max-width:128px" src="../images/psp.png" /></div>
</div>
</a>
</div>
</div>
</div>
And the CSS.
.tile {
width:100%;
display: inline-block;
box-sizing: border-box;
background: #fff;
padding: 15px;
margin-bottom: 20px;
color:#fff;
}
.title {
margin-top: 0px;
text-align:center;
}
.purple {
background: #5133AB;
}
.purple:hover {
background: #3e2784;
}
i believe if you just set the height of class .tile, it should work
.tile {
width:100%;
display: inline-block;
box-sizing: border-box;
background: #fff;
padding: 15px;
margin-bottom: 20px;
color:#fff;
height: 200px; // or whatever height you want all the tiles to be
}