I am new in Bootstrap, I am trying to do this responsive: A div, with 3 images centered (images have display: inline-block propertie).
But when I start resizing, in sm devices, the third image jump to a new line. I would like that in that case the three images were responsive, but something is not working. My HTML code:
<div class="row">
<div id="small-img" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 center">
<img src="img/img1.jpg" class="img-responsive inline-block" alt="Responsive image"/>
<img src="img/img2.jpg" class="img-responsive inline-block" alt="Responsive image"/>
<img src="img/img3.jpg" class="img-responsive inline-block" alt="Responsive image"/>
</div>
</div>
CSS:
.inline-block{ display: inline-block; }
.center{ text-align: center; }
Any suggestion please?
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.
Use the d-inline-block class to make an element display inline block. Use any of the d-*-inline-block classes to control WHEN the element should be inline block on a specific screen width. Resize the browser window to see the effect.
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.
The most common and traditional way (inline-block)The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
In the case of responsive images, the image(s) need an individual container that they can be sized into. In the example you have, there are three images in the one container, so they won't adapt individually to that single container. You could try something like:
.row li {
width: 33.3%;
float: left;
}
img {
border: 0 none;
display: inline-block;
height: auto;
max-width: 100%;
vertical-align: middle;
}
<div class="row">
<div id="small-img" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 center">
<ul>
<li>
<img src="http://placehold.it/150x100" class="img-responsive inline-block" alt="Responsive image" />
</li>
<li>
<img src="http://placehold.it/150x100" class="img-responsive inline-block" alt="Responsive image" />
</li>
<li>
<img src="http://placehold.it/150x100" class="img-responsive inline-block" alt="Responsive image" />
</li>
</ul>
</div>
</div>
I would rather go for width:100%
instead of class="img-responsive"
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