gpt4 book ai didi

Firefox 和 Chrome 中的 CSS 行高不同

转载 作者:技术小花猫 更新时间:2023-10-29 10:33:09 29 4
gpt4 key购买 nike

目标:仅在文本框中显示前四行。

我测试了JSFiddle Demo使用 Chrome 43.0.2357.132(64 位)和 Firefox 39,在 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>

最佳答案

您可以显式设置 line-height

line-height: 1.2;

工作示例(JSFiddle):

.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;
line-height: 1.2;
}
<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>

似乎 Firefox 的默认 line-height1.1,但 Chrome 的默认 line-height1.2.

关于Firefox 和 Chrome 中的 CSS 行高不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31386307/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com