我一直在创建一个网格,padding
用于排水沟。有时需要没有排水沟(完整width
图像),所以我只是创建了一个删除padding
.
问题是,当使用 a 时50%
width
,即使它正在使用border-box
,也不是真正的50%
。
简化的测试用例:
代码
*,
*:before,
*:after {
box-sizing: border-box;
}
.row {
zoom: 1;
&: before, &: after {
content: "";
display: table;
}
&:after {
clear: both;
}
}
.half {
width: 50%;
padding: 10px;
}
.no-pad {
padding: 0;
}
.column {
float: left;
}
img {
max-width: 100%;
height: 100%;
display: block;
}
.eq-height-container {
display: flex;
}
.eq-height-column {
flex: 1;
}
<div class="row eq-height-container">
<div class="column half eq-height-column" style="background-color: red;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
<div class="column half no-pad eq-height-column">
<img src="http://lorempixel.com/400/200" alt="">
</div>
</div>
<div class="row eq-height-container">
<div class="column half no-pad eq-height-column">
<img src="http://lorempixel.com/400/200" alt="">
</div>
<div class="column half eq-height-column" style="background-color: red;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa necessitatibus qui ea, quasi pariatur sed esse beatae porro in temporibus ipsum delectus, quisquam. Saepe sapiente, facere repellat tenetur quae aut.</p>
</div>
</div>
有没有一种简单的方法来解决这个问题?