我有一个主要的.features类的div,在这个div中,我有两个框,每个框的高度设置为160px,宽度不同。如下面的屏幕截图所示,两个框的末端与主div之间存在一个神秘的填充物:
填充约5像素-如果可能,我想删除此填充。我尝试添加保证金:0; 和填充:0; 到主要div以及两个内部框,但这没有用。
这是页面本部分的html:
<div class="features">
<div class="list-items"></div>
<div class="screenshot-box"></div>
</div>
CSS:
.features {
width: 980px;
margin: auto;
margin-top: 25px;
background-color: lightblue;
}
.list-items {
width: 280px;
height: 160px;
display: inline-block;
background-color: red;
}
.screenshot-box {
width: 583px;
height: 160px;
float: right;
padding-bottom: 0;
display: inline-block;
background-color: red;
}
这实际上与padding
或无关margin
。如果查看计算的样式示例,我们将看到height
元素本身的是164px
:
发生这种情况是因为您的内部元素设置为显示为inline-block
。这表示它们受的影响font-size
,最终font-size
导致父元素的高度大于内部元素的高度。
有两个修复程序:
font-size
of ,然后在内部元素中将其重置(通过为它们提供of ,或者使用您的默认大小)。0
.features
font-size
16
.features {
width: 980px;
margin: auto;
margin-top: 25px;
background-color: lightblue;
font-size: 0;
}
.list-items {
width: 280px;
height: 160px;
display: inline-block;
background-color: red;
font-size: 16px;
}
.screenshot-box {
width: 583px;
height: 160px;
float: right;
padding-bottom: 0;
display: inline-block;
background-color: red;
font-size: 16px;
}
<div class="features">
<div class="list-items"></div>
<div class="screenshot-box"></div>
</div>
.features
元素的height
的160px
本身以匹配其孩子。这样浏览器就不必自己计算高度。.features {
width: 980px;
margin: auto;
margin-top: 25px;
background-color: lightblue;
height: 160px;
}
.list-items {
width: 280px;
height: 160px;
display: inline-block;
background-color: red;
}
.screenshot-box {
width: 583px;
height: 160px;
float: right;
padding-bottom: 0;
display: inline-block;
background-color: red;
}
<div class="features">
<div class="list-items"></div>
<div class="screenshot-box"></div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句