简体   繁体   中英

Bootstrap 3 image responsive height not working

I have this div:

<section id="categorias">
 <div class="container content-section">
  <div class="row">
     <div  class="col-md-3">
        <img class="img img-responsive" src="img/catmusica.png"></img>
     </div>
     <div class="col-md-3">
        <img class="img-responsive" src="img/catpaisajes.png"></img>
     </div>
     <div class="col-md-3">
        <img class="img-responsive" src="img/catgrafiti.png"></img>
     </div>
     <div class="col-md-3" >
        <img class="img-responsive" src="img/catpoly.png"></img>
     </div>
  </div>
</div>
</section>

That looks like this: 在此处输入图片说明

And I want to maintain the 4 columns or at least 2 above and 2 below when I shrink the window but this happens: 在此处输入图片说明

I have only bootstraps css.

Thanks

You should also add grid system classes for smaller screens - col-sm-3 and col-xs-3. See following code:

<section id="categorias">
 <div class="container content-section">
  <div class="row">
     <div  class="col-md-3 col-sm-3 col-xs-3">
        <img class="img img-responsive" src="img/catmusica.png"></img>
     </div>
     <div class="col-md-3 col-sm-3 col-xs-3">
        <img class="img-responsive" src="img/catpaisajes.png"></img>
     </div>
     <div class="col-md-3 col-sm-3 col-xs-3">
        <img class="img-responsive" src="img/catgrafiti.png"></img>
     </div>
     <div class="col-md-3 col-sm-3 col-xs-3" >
        <img class="img-responsive" src="img/catpoly.png"></img>
     </div>
  </div>
</div>
</section>

working example

If you want to have only 2 columns on smaller screens then you need to apply this classes on div wrapping images:

<div  class="col-md-3 col-sm-6 col-xs-6">
   <img class="img img-responsive" src="img/catmusica.png"></img>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM