时间:2017-02-10 18:36:47

标签: twitter-bootstrap twitter-bootstrap-3 grid responsive masonry

这是我在这里的第一个问题,我希望你能帮助我。我正在尝试使用引导网格设置产品概述页面。我有大量屏幕尺寸的4个产品。对于较小的屏幕尺寸,我希望每行有2个产品。

诀窍是,我希望将产品详细信息放在行之间的折叠容器中,当我点击产品时,这些容器会打开。它适用于4种产品的大屏幕尺寸。但是如何实现折叠容器在行之后出现,我点击了我的产品,而不依赖于我每行的产品数量。在较小的尺寸上,即使我单击第一行中的产品,折叠的容器也会在第二行之后打开。

当我将每个折叠的容器放在标记中的产品后面时,当我将其打开时,它会推开其他产品。

对不起,这有点复杂,我希望你知道我的意思。

为了更好地理解,请查看我在笔下的笔。

我想尽量保持简单,我不知道该走哪条路?

http://codepen.io/auftakt/pen/PWxJVX

所有人的坦克。

$('.collapse-btn').on('click',function(){$('.collapse').collapse('hide');})
body {
  margin-top: 50px;
  overflow-y: scroll;
}

.img-responsive {
  width:100%;
}

.col-xs-6{
  margin-bottom: 20px;
}

.product-detail {
  width: 100%;
  height:300px;
  background-size: cover;
  background-position: center center;
}

.no-padding-left {
  padding-left: 0;
}

.product-collapse-wrap > div {
  margin-bottom: 20px;
}
<div class="container">
  <div class="row">
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-1" aria-expanded="false" aria-controls="Product-1">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-2" aria-expanded="false" aria-controls="Product-2">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-3" aria-expanded="false" aria-controls="Product-3">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-4" aria-expanded="false" aria-controls="Product-4">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
  </div>

  <div class="product-collapse-wrap">
    <div id="Product-1" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 1</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-2" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 2</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-3" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 3</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-4" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 4</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div class="row">
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-5" aria-expanded="false" aria-controls="Product-5">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-6" aria-expanded="false" aria-controls="Product-6">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-7" aria-expanded="false" aria-controls="Product-7">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
    <div class="col-md-3 col-xs-6">
      <a class="collapse-btn" data-toggle="collapse" href="#Product-8" aria-expanded="false" aria-controls="Product-8">
        <img class="img-responsive" src="http://placehold.it/600x600">
      </a>
    </div>
  </div>

  <div class="product-collapse-wrap">
    <div id="Product-5" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 5</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-6" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 6</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-7" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 7</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="Product-8" class="col-md-12 collapse">
      <div class="row">
        <div class="col-md-6 no-padding-left">
          <div class="img-responsive product-detail" style="background-image: url('http://placehold.it/800x600')"></div>
        </div>
        <div class="col-md-6">
          <h3>Product 8</h3>
          <ul>
            <li>Flachheizkörper</li>
            <li>Planheizkörper</li>
          </ul>
        </div>
      </div>
    </div>
  </div>

1 个答案:

答案 0 :(得分:1)

前段时间,我在这里回答了类似的问题:Bootstrap responsive grid layout (3 columns) with collapsed/hidden col-12 beneath each grid element

基本上,您必须将折叠的行放在适当的col-*下方以适合您的最小布局。所以在你的情况下:

  <div class="row">
            <div class="col-md-3 col-xs-6">
                <a href="#one" data-toggle="collapse"><img src="//placehold.it/600"></a>
            </div>
            <div class="col-md-3 col-xs-6">
                <a href="#two" data-toggle="collapse"><img src="//placehold.it/600"></a>
            </div>
            <div class="col-xs-12 overlay collapse" id="one">
                1
            </div>
            <div class="col-xs-12 overlay collapse" id="two">
                2
            </div>
            <div class="col-md-3 col-xs-6">
                <a href="#three" data-toggle="collapse"><img src="//placehold.it/600"></a>
            </div>
            <div class="col-md-3 col-xs-6">
                <a href="#four" data-toggle="collapse"><img src="//placehold.it/600"></a>
            </div>
            <div class="col-xs-12 overlay collapse" id="three">
               3
            </div>
            <div class="col-xs-12 overlay collapse" id="four">
               4
            </div>
   </div>

然后你需要一些额外的CSS来overlay折叠列,以便它在大屏幕上整行下的全宽。

演示:http://www.codeply.com/go/0QGguzIYCx

对于Bootstrap 4,由于 flexbox排序,这种情况更容易。 http://codeply.com/go/qdUGPVL4HJ(alpha 6)

http://codeply.com/go/TLJi5MxQ1E Bootstrap 4.0.0
http://codeply.com/go/EsRR1nGa36 Bootstrap 4.3.0