现代方法:flexbox
只需将以下 CSS 添加到容器元素(此处为div
):
div {
display: flex;
justify-content: space-between;
}
div {
display: flex;
justify-content: space-between;
}
<div>
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
</div>
旧方式(适用于古代浏览器 - 在 flexbox 之前)
text-align: justify;
在容器元素上使用。
然后将内容拉伸到 100% 宽度
标记
<div>
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
</div>
CSS
div {
text-align: justify;
}
div img {
display: inline-block;
width: 100px;
height: 100px;
}
div:after {
content: '';
display: inline-block;
width: 100%;
}
div {
text-align: justify;
}
div img {
display: inline-block;
width: 100px;
height: 100px;
}
div:after {
content: '';
display: inline-block;
width: 100%;
}
<div>
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
<img src="http://placehold.it/100x100" alt="" />
</div>