【发布时间】:2020-02-26 08:57:06
【问题描述】:
我有一个关于 flexbox 网格的简单问题,但我无法解决
我有这个代码:
<div class="grid-items row">
<div class="item item-50 col-xs-6">
<div class="text">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a
galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.
</div>
</div>
<div class="item col-xs-3">
<h2>Lorem Ipsum is simply dummy text</h2>
</div>
<div class="item item-image col-xs-3 ">
<img src="resources/images/pic1.jpg">
</div>
三列,每列的列间距为30px,第一列的宽度为50%,第二列和第三列的宽度为25%。显然,边距导致第三列溢出。是否可以在不改变宽度的情况下纠正这个问题?这是必要的,因为列有背景。
在这个练习中我不能修改 HTML,只能添加类...
列类的属性如下:
.col-xs-3 {
flex-basis: 25%;
max-width: 25%;
}
【问题讨论】:
-
大部分人使用的是
calc()来弥补。如果你有 3 个元素,你将有 2 个 30px 的排水沟。然后你会做calc(50% - (30px * 2) / 3)和calc(25% - (30px * 2) / 3) -
您是否尝试过更改
box-sizing定义?您可以使用border-box或content-box。