Margin problems with thumbnails in Bootstrap

大城市里の小女人 提交于 2019-12-07 12:30:47

问题


I'm doing this:

<div class="container-fluid">
  <div class="row-fluid">
    <div class="span12 well">
    <div class="row-fluid">
      <ul class="thumbnails">
        <?php 
          for($i=0; $i<count($rows); $i+=1){ // EVERY ODD BOOK STARTING AT 0
        ?>
        <li class="span4">
          <div class="thumbnail">
            <img src="http://placehold.it/320x200" alt="ALT NAME">
            <div class="caption">
              <h3><?php echo $rows[$i]['Title']; ?></h3>
              <p>Seller: <?php echo $rows[$i]['FirstName'] . " " . $rows[$i]['LastName']; ?> </p>
              <p>Email: <?php echo $rows[$i]['Email']; ?></p>
              <p>Phone: <?php echo $rows[$i]['PhoneNumber']; ?></p>
              <p>Condition: <?php echo $rows[$i]['BookCondition']; ?></p>
              <p align="center"><a href="#" class="btn btn-primary btn-block">Open</a></p>
            </div>
          </div>
        </li> 
          <?php
        }
      ?>   
      </ul>
    </div>
</div>

and whenever I have more than 3 items, the thumbnails get misaligned by what looks to be a left margin on the second row..

See image:


回答1:


I would guess that the bootstrap adds a left margin to all elements, except for the first one. You could add a style like this:

ul.thumbnails li.span4:nth-child(3n + 4) {
  margin-left : 0px;
}

But be aware that this is not compatible with older ie browsers...

another way you could do it, is to add a class to every forth li in your php loop (call it something like .noLeftMargin, and set the css accordingly.




回答2:


Remove the row div before .thumbnails and you won't need extra css.




回答3:


also you can check Bootstrap's documentation on resets.

Bootstrap.com > CSS > Grids > Responsive Column Resets

http://getbootstrap.com/css/#grid-responsive-resets

most of the time it can be solved with Bootstrap's .clearfix class



来源:https://stackoverflow.com/questions/15576483/margin-problems-with-thumbnails-in-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!