Responsive image align center bootstrap 3

前端 未结 18 1014
半阙折子戏
半阙折子戏 2020-11-29 14:16

I do a catalog using Bootstrap 3. When displayed on tablets, the product images look ugly because of their small size (500x500) and a width of 767 pixels in the browser. I w

相关标签:
18条回答
  • 2020-11-29 15:13

    Add only the class center-block to an image, this works with Bootstrap 4 as well:

    <img src="..." alt="..." class="center-block" />
    

    Note: center-block works even when img-responsive is used

    0 讨论(0)
  • 2020-11-29 15:13

    Simply put all the images thumbnails inside a row/col divs like this:

    <div class="row text-center">
     <div class="col-12">
      # your images here...
     </div>
    </div>
    

    and everything will work fine!

    0 讨论(0)
  • 2020-11-29 15:14

    If you're using Bootstrap v3.0.1 or greater, you should use this solution instead. It doesn't override Bootstrap's styles with custom CSS, but instead uses a Bootstrap feature.

    My original answer is shown below for posterity


    This is a pleasantly easy fix. Because .img-responsive from Bootstrap already sets display: block, you can use margin: 0 auto to center the image:

    .product .img-responsive {
        margin: 0 auto;
    }
    
    0 讨论(0)
  • 2020-11-29 15:16

    The more exact way applied to all Booostrap objects using standard classes only would be to not set top and bottom margins (as image can inherit these from parent), so I am always using:

    .text-center .img-responsive {
        margin-left: auto;
        margin-right: auto;
    }
    

    I have also made a Gist for that, so if any changes will apply because of any bugs, update version will be always here: https://gist.github.com/jdrda/09a38bf152dd6a8aff4151c58679cc66

    0 讨论(0)
  • 2020-11-29 15:19

    Try this code it will work for small icons too with bootstrap 4 because there is no center-block class is bootstrap 4 so try this method it will be helpful. You can change the position of the image by setting the .col-md-12 to .col-md-8 or .col-md-4, it's upto you.

    <div class="container">
           <div class="row">
              <div class="col-md-12">
                <div class="text-xs-center text-lg-center">
               <img src="" class="img-thumbnail">
               </div>
              </div>
           </div>
      </div>
    
    0 讨论(0)
  • 2020-11-29 15:19

    Try this:

    .img-responsive{
        display: block;
        height: auto;
        max-width: 100%;
    	  margin:0 auto;
    }
    .Image{
      background:#ccc;
      padding:30px;
    }
    <div class="Image">
      <img src="http://minisoft.com.bd/uploads/ourteam/rafiq.jpg" class="img-responsive" title="Rafique" alt="Rafique">
    </div>

    0 讨论(0)
提交回复
热议问题