在下面的代码中:
<a href="*">
<h3>My really really long header</h3>
<img src="thumbnail.png" width="150" height="100" />
</a>
h3
溢出了它的大小。如果我将溢出设置为隐藏,则会在 h3
的底部添加一个额外的边距。如果我将标题更改为短标题,则不会出现额外的底部边距。
在搜索 SO 之后,我发现了一些关于折叠边距的信息。但重点是 img
和 h3
都没有边距。
这是 CSS:
h3 {
width: 300px;
height: 40px;
line-height: 40px;
padding: 0 0 0 10px;
margin: 0;
display: inline-block;
width: 150px;
background-color: #0f0;
}
a {
position: relative;
display: block;
margin-bottom: 20px;
padding: 4px;
border: 1px solid #000;
width: 160px;
height: auto;
}
img {
background-color: #00f;
}
如果我将标记 a
的 font-size
设置为零,则不会显示额外的边距。
问题:有没有合适的方法(不设置font-size: 0
)来解决这个问题?
最佳答案
您将 h3
设置为 inline-block
。默认情况下,inline-block
遵循line-height
和font-size
。将您的 h3
更改为显示 block 。
CSS:
h3 {
width: 300px;
height: 40px;
line-height: 40px;
padding: 0 0 0 10px;
margin: 0;
display: block;
width: 150px;
background-color: #0f0;
overflow:hidden;
}
关于html - overflow hidden 的边距底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31149640/