Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap - how to stop images overlapping on smaller window size?

I have this:

<div id="members">
    <div class="container-fluid">
        <div class="row">
            <div id="members" class="col-md-12 text-center">
                <h3>Text</h3>
                <div class="col-lg-2 col-md-2">
                <img src="images/1.png">
                </div>
                <div class="col-md-2">
                <img src="images/1.png">
                </div>
                <div class="col-md-2">
                <img src="images/1.png">
                </div>
                <div class="col-md-2">
                <img src="images/1.png">
                </div>
                <div class="col-md-2">
                <img src="images/1.png">
                </div>
                <div class="col-md-2">
                <img src="images/1.png">
                </div>
         </div>
      </div>
    </div>
</div>

However when I make the browser window narrower, they start to overlap. How can I control this? And how can I remove some of the images on the smaller browser window?

Thanks

like image 362
Joe Sgg Avatar asked Sep 06 '25 03:09

Joe Sgg


2 Answers

Bootstrap 4 uses an .img-fluid class for responsive images, from the docs

<img src="images/1.png" class="img-fluid" />
like image 78
Mike Hague Avatar answered Sep 07 '25 21:09

Mike Hague


you need to add img-responsive class to the images, and hidden-xs to the container div (in case you want to hide in mobile). Hidden-sm for tablet, hidden-md for small desktop, and hidden-lg for large desktop:

<div class="col-md-2 hidden-xs">
   <img src="http://via.placeholder.com/350x150/880000" class="img-responsive">
</div>

Pen: https://codepen.io/giannidk/pen/rwpmpx?editors=1100

like image 26
gianni Avatar answered Sep 07 '25 19:09

gianni