CSS 字体大小为 100% 时的行高默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16163788/
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
Line height default value if font size is 100%
提问by grigno
I must override the body style of my page:
我必须覆盖我页面的正文样式:
body{
font-size:14px;
line-height:20px;
}
override:
覆盖:
body{
font-size:100%;
line-height:?????;
}
What is the defualt value of line-height
property if I specified font-size:100%
?
line-height
如果我指定,财产的默认值是font-size:100%
多少?
Is there a strict relation between this properties ?
这个属性之间有严格的关系吗?
回答by Daniel Imms
The default line-height
is normal
, so use:
默认line-height
为normal
,因此请使用:
body {
font-size: 100%;
line-height: normal;
}
FYI, you can confirm this if you have Chrome by opening up a website, inspecting the <body>
element and viewing the inherited computed styles.
仅供参考,如果您有 Chrome,您可以通过打开网站、检查<body>
元素并查看继承的计算样式来确认这一点。
回答by Willem Mulder
Set a unitless value of 1
, which will multiply the calculated font-size (i.e. how big the font turns out to be) with 1, making for a high-enough line-height.
设置一个无单位的值1
,这会将计算出的字体大小(即字体的大小)乘以 1,从而获得足够高的行高。
You can also use 1.5
for a little more spacing.
您也可以使用1.5
更多的间距。
So to finish your code it would be
所以要完成你的代码,它将是
body{
font-size:100%;
line-height: 1.5;
}
See the part on at https://developer.mozilla.org/en-US/docs/CSS/line-heightfor more details. Using a unitless number is stated as the preferred way of setting line-height.
有关更多详细信息,请参阅https://developer.mozilla.org/en-US/docs/CSS/line-height上的部分。使用无单位数被认为是设置行高的首选方式。
回答by Nabil Kadimi
Values
normal
Depends on the user agent. Desktop browsers (including Firefox) use a default value of roughly
1.2
, depending on the element'sfont-family
....
价值观
normal
取决于用户代理。桌面浏览器(包括 Firefox)使用默认值大致为
1.2
,具体取决于元素的font-family
....
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#Values
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#Values
回答by Bernie
The default line height is roughly ~1.1em (see here).
默认行高大约为 ~1.1em(请参阅此处)。
You can change the relationship between the line-height and the font-size however, using for example:
但是,您可以更改行高和字体大小之间的关系,例如:
body {
font: 100%/1.618;
}
To take a more in depth look at the relationship between line-height and font-size, a good place to start would be:
http://demosthenes.info/blog/606/Molten-Leading-Exploring-The-CSS-Relationship-Between-Font-Size-Line-Height-and-Margin
要更深入地了解行高和字体大小之间的关系,一个好的起点是:http:
//demosthenes.info/blog/606/Molten-Leading-Exploring-The-CSS-Relationship -在字体大小-行高和边距之间
回答by Arbel
You can use relative line-height
您可以使用相对 line-height
If your original sizes have been font-size:14px;
and line-height:20px;
and you want to keep the same proportions you can use 1 * (20/14) em so line-height:1.42em;
如果您的原始尺寸已经font-size:14px;
和line-height:20px;
你想保持相同的比例可以用1 *(20/14)EM使line-height:1.42em;
body{
font-size:100%;
line-height:1.42em;
}