[英]How to stop a header and lower text from flowing around an upper left-floated img element
Suppose the order of the layout like so:假设布局的顺序是这样的:
H3
<LEFT-FLOATED IMG> <text>
<H3>
<LEFT-FLOATED IMG> <text>
Now, for lower screen sizes, the above layout produces no problems:现在,对于较小的屏幕尺寸,上述布局不会产生任何问题:
However, once the screen is resized to a higher dimension, the following problem occurs:但是,一旦将屏幕调整到更高的尺寸,就会出现以下问题:
This is the source code, and note that I am using Bootstrap-4 to achieve float-left, etc:这是源代码,请注意,我使用Bootstrap-4来实现向左浮动等:
<h3>Pigmentary variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pigmentary variegation.jpg" alt="pigmentary_variegation_example">
<p>Text for pigmentary variegation</p>
<h3>Pathological variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pathological_variegation.jpg" alt="mosaic virus">
<p>Text for pathological variegation</p>
How could I prevent text beyond the lower H3 element from wrapping around the above left-floated image?如何防止下方 H3 元素之外的文本环绕上方的左浮动图像?
将clear:both
添加到您的 h3
h3 {clear:both;}
Wrap each section in a div which has display:block;
将每个部分包装在一个具有
display:block;
的 div 中display:block;
by default:默认情况下:
<div>
<h3>Pigmentary variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pigmentary variegation.jpg" alt="pigmentary_variegation_example">
<p>Text for pigmentary variegation</p>
</div>
<div>
<h3>Pathological variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pathological_variegation.jpg" alt="mosaic virus">
<p>Text for pathological variegation</p>
</div>
Alvaro answer is good, but in some case it is more useful to wrap your code with a div with this class: Alvaro 的回答很好,但在某些情况下,使用此类用 div 包装代码更有用:
.clearfix::before, .clearfix::after {
content: "";
display: table;
border-collapse: collapse;
}
You have 2 option in less.你有 2 个选项。
1: you can use "clearfix" property in your html codes (with some css codes) like this: 1:您可以在您的 html 代码(带有一些 css 代码)中使用“clearfix”属性,如下所示:
css: css:
.clearfix {
clear: both;
}
html: html:
<h3>Pigmentary variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pigmentary variegation.jpg" alt="pigmentary_variegation_example" />
<p>Text for pigmentary variegation</p>
<div class="clearfix"></div> <!--This is your clear code for clear float's gap. -->
<h3>Pathological variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pathological_variegation.jpg" alt="mosaic virus" />
<p>Text for pathological variegation</p>
2: use "div" for your sections. 2:为您的部分使用“div”。 (every section should have 1 parent div).
(每个部分都应该有 1 个父 div)。 div can create a block with your section that have display block by default.
div 可以使用您的部分创建一个块,默认情况下具有显示块。 so your code is like this:
所以你的代码是这样的:
<div>
<h3>Pigmentary variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pigmentary variegation.jpg" alt="pigmentary_variegation_example" />
<p>Text for pigmentary variegation</p>
</div>
<div>
<h3>Pathological variegation</h3>
<img class="img-fluid float-left mr-2 mb-0" src="../assets/image/articles/variegation/pathological_variegation.jpg" alt="mosaic virus" />
<p>Text for pathological variegation</p>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.