Bootstrap 3.3.7 md上的列布局问题

时间:2018-03-08 00:13:11

标签: html css twitter-bootstrap-3 responsive-design responsive

这是我的bootstrap网站的当前布局。不幸的是,它不起作用,因为列完全取决于md尺寸。

Here是当前视图。

我的目标是让它们按照md尺寸分为2列。所以布局将是image+text;new column;image+text;new column;image+text

        <div class="row">
            <div class="col-lg-4 col-md-6 coko">
                <img src="images/malinica.jpg" class="img-responsive img-rounded" alt="Cokol">
                <a class="link" href="#"><div class="preko">
                <h3 class="text-center">Cakes</h3></div></a> 
            </div>
            <div class="col-lg-4 col-md-6 coko">
                <p class="text-center">In 1995, <a href="index.html">The Rolling Pin</a> 
                opened its first location on a quiet street corner in the heart of 
                Munich. From its inception, The Rolling Pin has been cherished for its 
                classic Germany baked goods, vintage decor and warm, invitig atmosphere.
                </p>
            </div>
            <div class="col-lg-4 coko col-md-6">
                <img src="images/cupcake.jpg" class="img-responsive img-rounded" alt="Coko">
                <a class="link" href="#"><div class="preko">
                <h3 class="text-center">Muffins</h3>
                </div></a>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 coko col-md-6">
                <h3 class="text-center">We stand for organic</h3>
                <p class="text-center">The Rolling Pin has a whole line of organic 
                desserts and drinks that prove that eating organic can taste just as 
                delicious.</p>
            </div>
        <div class="col-lg-4 col-md-6 coko">
            <img src="images/kafa.jpg" class="img-responsive img-rounded" alt="Coko">
            <a class="link" href="#"><div class="preko">
            <h3 class="text-center">Drinks</h3>
            </div></a>
        </div>
        <div class="col-lg-4 col-md-6 coko">
            <h3 class="text-center">Pet friendly</h3>
            <p>If you have a dog or cat, this is the right place for 
            you. Except our place, we offer you a special menu for your pet.</p>
            </div>          
        </div>

2 个答案:

答案 0 :(得分:1)

这是因为min-height问题。添加额外的divmin-height

min-height div添加.coko

答案 1 :(得分:1)

看看这是否有帮助: https://codepen.io/panchroma/pen/geYeep

这样的布局有两个挑战。

首先,您希望将所有元素放在同一行中,其次,您需要允许列具有不同的高度。第n个子选择器和一些@media选择器是一种操作CSS并使其工作的有效方法。

HTML - 这与你的完全相同,只是注释了几行,所以所有元素都在同一行

 <div class="row">
  <div class="col-lg-4 col-md-6 coko">
    <img src="http://www.fillmurray.com/500/400" class="img-responsive img-rounded" alt="Cokol">
    <a class="link" href="#">
      <div class="preko">
        <h3 class="text-center">Cakes</h3>
      </div>
    </a>
  </div>
  <div class="col-lg-4 col-md-6 coko">
    <p class="text-center">In 1995, <a href="index.html">The Rolling Pin</a> opened its first location on a quiet street corner in the heart of Munich. From its inception, The Rolling Pin has been cherished for its classic Germany baked goods, vintage decor and warm, invitig
      atmosphere.
    </p>
  </div>
  <div class="col-lg-4 coko col-md-6">
    <img src="http://www.fillmurray.com/500/200" class="img-responsive img-rounded" alt="Coko">
    <a class="link" href="#">
      <div class="preko">
        <h3 class="text-center">Muffins</h3>
      </div>
    </a>
  </div>
  <!--         </div> -->
  <!--         <div class="row"> -->
  <div class="col-lg-4 coko col-md-6">
    <h3 class="text-center">We stand for organic</h3>
    <p class="text-center">The Rolling Pin has a whole line of organic desserts and drinks that prove that eating organic can taste just as delicious.
    </p>
  </div>
  <div class="col-lg-4 col-md-6 coko">
    <img src="http://www.fillmurray.com/500/300" class="img-responsive img-rounded" alt="Coko">
    <a class="link" href="#">
      <div class="preko">
        <h3 class="text-center">Drinks</h3>
      </div>
    </a>
  </div>
  <div class="col-lg-4 col-md-6 coko">
    <h3 class="text-center">Pet friendly</h3>
    <p>If you have a dog or cat, this is the right place for you. Except our place, we offer you a special menu for your pet.</p>

  </div>
</div>  

CSS - 第一个媒体查询确保每个第三列在md视口中向左浮动到新行的开头。

另一种方法是补偿HTML中第二行div的删除

@media (max-width: 1199px) {
  .row div:nth-child(odd){
    clear:left
  }
}


@media (min-width: 1200px) {
  .row div:nth-child(3n + 4){
    clear:left
  }
}   
祝你好运!