我正在尝试使用bootstrap 4构建以下布局,我希望左侧有2个更大的列,然后右侧有4个组合在一起但是它们的高度togetehr不能超过前2个的高度。
除了我不能让它发挥作用。
这就是我想要的:
这基本上就是我得到的:
https://codepen.io/anon/pen/ZrBpze
<section id="mu-featured">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur. <a href="#" class="">Call to action!</a></p>
</div>
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur. <a href="#" class="">Call to action!</a></p>
</div>
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur. <a href="#" class="">Call to action!</a></p>
</div>
<div class="col-md-4 col-sm-6">
<img src="img/picture.jpg" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur. <a href="#" class="">Call to action!</a></p>
</div>
</div>
</div>
</section>
答案 0 :(得分:1)
您没有指定他们在较小的屏幕上应该如何表现,而是回答您的问题:您需要嵌套最正确的项目,如下面的代码所示。
换句话说,您要做的事情称为“嵌套”。不订购。
要嵌套,您将.row
放入一列,然后在该嵌套行中放入至少一个其他col-*
(下面的第二个代码片段会产生稍微不同的结果):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<section id="mu-featured">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">
<img src="https://placehold.it/235" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-6">
<img src="https://placehold.it/235" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero rem accusamus voluptatibus, nihil
unde maiores sunt nisi. Assumenda, consectetur.
</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-12">
<div class="row">
<div class="col-12">
<img src="https://placehold.it/85" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero. <a href="#" class="">Call to action!</a></p>
</div>
<div class="col-12">
<img src="https://placehold.it/85" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero. <a href="#" class="">Call to action!</a></p>
</div>
<div class="col-12">
<img src="https://placehold.it/85" alt="" style="height: 85px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Illo suscipit facilis ipsum ullam reiciendis odio error
iste neque ratione libero. <a href="#" class="">Call to action!</a></p>
</div>
</div>
</div>
</div>
</div>
</section>
这是另一个产生稍微不同结果的版本(点击下面的“运行代码段”按钮并展开到整页):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<section id="mu-featured">
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-6">
<img src="https://placehold.it/235" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo suscipit facilis ipsum ullam reiciendis odio error iste neque ratione libero rem accusamus voluptatibus, nihil unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo suscipit facilis ipsum ullam reiciendis odio error iste neque ratione libero rem accusamus voluptatibus, nihil unde maiores sunt nisi. Assumenda, consectetur.
</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-6">
<img src="https://placehold.it/235" alt="" style="height: 235px">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo suscipit facilis ipsum ullam reiciendis odio error iste neque ratione libero rem accusamus voluptatibus, nihil unde maiores sunt nisi. Assumenda, consectetur.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo suscipit facilis ipsum ullam reiciendis odio error iste neque ratione libero rem accusamus voluptatibus, nihil unde maiores sunt nisi. Assumenda, consectetur.
</p>
<a href="#" class="">Call to action!</a>
</div>
<div class="col-md-4 col-sm-12">
<div class="row">
<div class="col-auto">
<img src="https://placehold.it/85" alt="" style="height: 85px">
</div>
<div class="col">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br> <a href="#" class="">Call to action!</a></p>
</div>
<div class="w-100"></div>
<div class="col-auto">
<img src="https://placehold.it/85" alt="" style="height: 85px">
</div>
<div class="col">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br> <a href="#" class="">Call to action!</a></p>
</div>
<div class="w-100"></div>
<div class="col-auto">
<img src="https://placehold.it/85" alt="" style="height: 85px">
</div>
<div class="col">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br> <a href="#" class="">Call to action!</a></p>
</div>
<div class="w-100"></div>
<div class="col-auto">
<img src="https://placehold.it/85" alt="" style="height: 85px">
</div>
<div class="col">
<h1>Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br> <a href="#" class="">Call to action!</a></p>
</div>
</div>
</div>
</div>
</div>
</section>
在第二个代码段中,小图像及其文本内容分为2个不同的列,<div class="w-100"></div>
用作小屏幕的分隔符。 w-100
表示“宽度:100%”。