html - 为什么 margin-left 不适用于 float:left 图像右侧的块元素?
问题描述
在下面的代码中,我有一个 div 中的图像向左浮动。由于图像 div 上的浮动,div 中的一些文本会右转。两者都是块级元素。
我知道我可以通过对图像应用边距来添加它们之间的分隔。但是为什么我不能通过对文本 div 应用左边距来添加分隔符呢?
jsfiddle:https ://jsfiddle.net/HumanJHawkins/r5p3197t/8/
body {
margin: 5vw;
}
h1 {
text-align: center;
border-bottom: 1px solid black;
margin-bottom: 4vw;
}
.container:after {
content: "";
display: block;
clear: both;
}
.thingImage {
float: left;
width: 20%;
}
.thingImage img {
max-width: 100%;
}
.thingDesc {
display: block;
width: 80%;
}
<h1>Things List</h1>
<div class="container">
<div class="thingImage">
<img src="https://i.postimg.cc/RZMY6kCf/bw-Dog-Sleepy.jpg" />
</div>
<div class="thingDesc">
<h2>Thing 1</h2>
<p>Thing one is the first thing.</p>
</div>
</div>
<div class="container">
<div class="thingImage">
<img src="https://i.postimg.cc/wj0Ghw3r/desaturated-Monkey.jpg" />
</div>
<div class="thingDesc">
<h2>Thing 2</h2>
<p>Thing two is the second thing.</p>
</div>
</div>
<div class="container">
<div class="thingImage">
<img src="https://i.postimg.cc/PrbcqXHT/desaturated-Spider.jpg" />
</div>
<div class="thingDesc">
<h2>Thing 3</h2>
<p>Thing one is the third thing.</p>
</div>
</div>
解决方案
推荐阅读
- jquery - 将图像加载过程显示为页面加载百分比
- python-3.x - Scikit-Learn GroupShuffleSplit 未按指定组分组
- php - 需要能够从表单输入中按表中的字段进行搜索
- c# - HttpClient 不返回 URI 的 json 值
- clojure - 是否可以将两个函数应用于 Clojure 中的列表?
- javascript - Angular FormControl 模式验证器不适用于正则表达式
- java - 如何获取输入元素的文本属性?- 网络驱动程序
- amazon-web-services - 命令“维护:安装”未定义
- node.js - 如果存在,则在 mongodb 中增加嵌套字段值或创建嵌套字段
- php - 带有laravel的网址中的问号