【发布时间】:2014-12-07 16:03:22
【问题描述】:
第一个li 的高度是45px。第二个li 是46px。为什么?
div {
height: 45px;
line-height: 45px;
background-color: #b6ff00;
}
li {
line-height: 45px;
list-style: none;
float: left;
}
li > a {
width: 200px;
line-height: inherit;
display: block;
text-decoration: none;
background-color: #ff6a00;
}
li:first-child > a {
background-color: #00ffff;
}
<div>
<ul>
<li>
<a href="#">dfdd</a>
</li>
<li>
<a href="#"><small>sdaf</small>abc</a>
</li>
</ul>
</div>
【问题讨论】:
-
因为
<small>文本的半前导比它共享行的支柱的半前导大1px,所以从支柱顶部到底部的距离文本的行内框比它们各自的行高大 1px。 -
我在浏览器中don't see this being the case。两个 LI 元素的高度均为 45 像素。您能否在问题中包含浏览器信息以及可能显示 46 像素高度的屏幕截图?
-
您可以使用
vertical-align: top或vertical-align: bottom修复它。 -
@MichaelT 第二个比第一个高 1 像素(至少在 Firefox 上)。但是 devtools 说两者都有计算
line-height的45px。 -
@Alohci 如何解决这个问题?我添加了垂直对齐,但无效