什么是行高:1?

fre*_*ara 33 css

这是一个关于线高的任命的问题.

我开始研究css.line-height:经常可以找到指定20px或单位的示例.它有时是行高:有1个没有单位的东西,但这变成了什么样的意思?

Hai*_*vgi 34

可能的值

号码:

设置将与当前字体大小相乘的数字,以设置线条之间的距离

长度 :

设置线之间的固定距离

%:

以当前字体大小的%为单位设置行之间的距离

来自http://www.w3schools.com/css/pr_dim_line-height.asp

  • 如果设置行高**不带单位**,结果是**行高值乘以元素的字体大小**。line-height 属性可以接受无单位值。这是一篇详细介绍 [line-height 属性](https://kolosek.com/css-line-height/) 的好文章。 (2认同)

ins*_* me 8

似乎line-height不需要一个单元(详细的文章).

属性line-height可以接受无单位数值.您也可以给出行高联合值,但通常不应该.但无单位的数字对于这个属性来说还不错.


Geo*_*ley 8

另请注意:"1"不等于"normal" - 1与字体大小完全相同,因此多行元素(如段落)中的行将相互贴合,而正常情况下会增加线之间的预期间距.

使用字体速记:

font: font-style font-variant font-weight font-size/line-height font-family;
Run Code Online (Sandbox Code Playgroud)

如果未指定,则将line-height默认为normal.例如:

body{
    line-height:1; /* as seen in Eric Meyer's reset css */
}
p{
    font:normal normal normal 14px "Times New Roman", Times, serif;
}
Run Code Online (Sandbox Code Playgroud)

将导致所有段落具有正常的行高,覆盖身体的1集,而

p{
    font:normal normal normal 14px/1 "Times New Roman", Times, serif;
}
Run Code Online (Sandbox Code Playgroud)

将保留行高1(在此示例中为14px).


jit*_*ter 7

如果没有提供单位,例如,"line-height: 1.5"行之间的距离设置为该数字乘以当前字体大小。

1.5 倍字体大小


mer*_*uro 6

根据w3schoolsw3.org line-height:1; 有效且含义如下: 设置一个数字,该数字将与当前字体大小相乘以设置行之间的距离。