设置line-height:1;
和margin:0;
时,小写的p和g会使块级元素溢出。 但是,内联元素没有溢出。 为什么会有这种差异?
null
.large {
font-size: 116px;
line-height: 1;
overflow: hidden;
}
* {
margin: 0px;
padding: 0px;
border-width: 0px;
}
<body>
<div class="large">
block pPgG
</div>
<div>
<span class="large">
inline pPgG
</span>
</div>
</body>
null
overflow
只适用于块级元素ref,内联元素的内容不能溢出,因为您不能使内联元素的高度小于其内容,因为您不能在内联元素上定义高度,而高度是由内容ref自动定义的
添加边框将清楚地显示这一点:
null
.large {
font-size: 50px;
line-height: 1;
}
.overflow {
overflow: hidden;
border:1px solid green;
}
body > div {
margin:20px;
outline:2px solid red;
}
<body>
<div class="overflow large">
Testing: pPgG
</div>
<div>
<span class="overflow large">
Testing: pPgG
</span>
</div>
</body>