【问题标题】:Bootstrap 3.3.7 column layout problems on mdBootstrap 3.3.7 md 上的列布局问题
【发布时间】:2018-03-08 23:42:30
【问题描述】:

这是我的引导网站的当前布局。不幸的是,它不起作用,因为列在 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>

【问题讨论】:

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


    【解决方案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
      }
    }   
    

    祝你好运!

    【讨论】:

      【解决方案2】:

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

      为您的.coko div 添加min-height

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-02
        • 2019-05-23
        • 2016-04-22
        • 2020-05-22
        • 2012-02-10
        • 2021-06-07
        • 2020-12-19
        • 1970-01-01
        相关资源
        最近更新 更多