Bootstrap 4 文本环绕另一列/图像
Posted
技术标签:
【中文标题】Bootstrap 4 文本环绕另一列/图像【英文标题】:Bootstrap 4 text wrapping around another column/images 【发布时间】:2018-07-20 04:43:35 【问题描述】:您好,我有一个问题,我的文本没有使用 bootstrap 4 环绕我的图像。而不是环绕它停留在右侧,也许我不应该将图像放在单独的列中?
这两个图像必须在彼此的顶部,但我需要文本在它的右侧,当屏幕变小并且文本高度大于两个图像的高度时,它需要环绕他们。
还有我怎样才能使图像在您调整浏览器大小时不会调整大小,以便它们始终保持相同的大小。
<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="about">
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-12 col-sm-12">
<h1>About</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>
</div>
<div class="col-lg-6 col-md-12 col-sm-12">
<div class="row">
<div class="col-12">
<h1>About</h1>
</div>
<div class="col-6">
<div class="row">
<div class="col-12">
<img src="http://via.placeholder.com/350x150" style="width: 100%;
margin-bottom: 25px;" class="about-img">
</div>
<div class="col-12">
<img src="http://via.placeholder.com/350x150" style="width: 100%;
margin-bottom: 25px;" class="about-img">
</div>
</div>
</div>
<div class="col-6">
<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>
</div>
</div>
</div>
</div>
</div>
</section>
【问题讨论】:
您应该阅读 Bootstrap 文档。这里缺乏大量知识。 【参考方案1】:你应该把图片和文字放在同一个col
。在图片上使用float-left
,让文字环绕它们。
https://www.codeply.com/go/GNkJjFkPfP
<div class="row">
<div class="col-12 mb-3">
<img src="http://via.placeholder.com/350x150" class="float-left mr-3 about-img">
<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>
</div>
<div class="col-12 mb-3">
<img src="http://via.placeholder.com/350x150" class="float-left mr-3 about-img">
<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>
</div>
</div>
看起来你还有很多不必要的 row>col 嵌套。如果您不想调整图像大小,请删除 width:100%
。
【讨论】:
非常感谢,这很好用,而且有了这些信息,我也能够清理很多其他代码!以上是关于Bootstrap 4 文本环绕另一列/图像的主要内容,如果未能解决你的问题,请参考以下文章
Bootstrap:如何获得具有 100% 高度的另一列的列