【发布时间】:2015-10-01 21:22:54
【问题描述】:
目标:仅在文本框中显示前四行。
我用 Chrome 43.0.2357.132(64 位)和 Firefox 39 测试了 JSFiddle Demo,在 Chrome 中,文本框完美显示了前 4 行(其余行被隐藏),而在 Firefox 中,line-height 显得更大,因此第四行被剪掉了。
如何用 CSS 解决这个问题?
.txt {
width:300px;
height:48px;
overflow:hidden;
border-bottom-style:solid;
border-bottom-width:1px;
border-bottom-color:#aaaaaa;
margin-bottom:2em;
font-size:0.8em;
}
<div class="txt">
This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text. This is just a temporary text.
</div>
【问题讨论】:
-
所有浏览器的默认字体大小都一样吗?您在
px中设置了高度,但在em中设置了字体大小。您可能希望将 line-height 声明为(使其覆盖任何默认值,如果给定)。
标签: css google-chrome firefox cross-browser