CSS 什么是行高:1?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1000398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is line-height:1?
提问by freddiefujiwara
It is a question about the appointment of line-height.
这是一个关于行高的指定问题。
I began study of css. line-height: Examples appointing 20px or a unit are often found. It is sometimes line-height: There are 1 and a thing without a unit, but what kind of meaning does this become?
我开始研究css。line-height:经常可以找到指定 20px 或一个单位的例子。有时是 line-height: 有 1 和没有单位的东西,但是这变成什么样的意思?
回答by Haim Evgi
Possible Values
可能的值
number:
号码:
Sets a number that will be multiplied with the current font-size to set the distance between the lines
设置一个数字,该数字将与当前字体大小相乘以设置行之间的距离
length:
长度:
Sets a fixed distance between the lines
设置线之间的固定距离
%:
%:
Sets a distance between the lines in % of the current font size
以当前字体大小的百分比设置行之间的距离
take from http://www.w3schools.com/css/pr_dim_line-height.asp
回答by George Langley
Also note: "1" does not equal "normal" - 1 is exactly the same height as the font-size, so the lines in a multi-line element such as a paragraph will be snug up against each other, while normal adds the expected spacing between the lines.
另请注意:“1”不等于“正常” - 1 与字体大小完全相同,因此多行元素(例如段落)中的行将彼此紧贴,而正常添加行之间的预期间距。
Using the font shorthand:
使用字体速记:
font: font-style font-variant font-weight font-size/line-height font-family;
appears to default the line-height to normal if it isn't specified. For example:
如果未指定,则似乎默认行高为正常。例如:
body{
line-height:1; /* as seen in Eric Meyer's reset css */
}
p{
font:normal normal normal 14px "Times New Roman", Times, serif;
}
will result in all paragraphs having a normal line-height, overriding the 1 set for the body, while
将导致所有段落具有正常的行高,覆盖正文的 1 集,而
p{
font:normal normal normal 14px/1 "Times New Roman", Times, serif;
}
will retain the line-height of 1 (which in this example would be 14px).
将保留 1 的行高(在本例中为 14px)。
回答by instanceof me
It seems that line-height
doesn't need a unit (detailled article).
The property line-height can accept unitless number values. You can also give line-height united values, though generally you shouldn't. But unitless numbers are just fine for this property.
属性 line-height 可以接受无单位的数值。您还可以提供行高统一值,但通常不应该这样做。但是无单位数对这个属性来说很好。
回答by merkuro
回答by jitter
If no unit is supplied e.g. "line-height: 1.5"
the distance between the lines is set as this number multiplied with the current font size.
如果没有提供单位,例如"line-height: 1.5"
行之间的距离设置为这个数字乘以当前字体大小。
1.5 x font-size
1.5 x 字体大小
回答by Joey
It's a multiple of the font size. From the CSS 2.1 Candidate recommendation: ?The used value of the property is this number multiplied by the element's font size.?
它是字体大小的倍数。来自 CSS 2.1 Candidate 建议: ? 属性的使用值是这个数字乘以元素的字体大小。?