Html CSS中带斜杠的字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/701732/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:32:31  来源:igfitidea点击:

Size of font in CSS with slash

htmlcsssize

提问by Alex

What does the slash mean here:

这里的斜线是什么意思:

font: 100%/120%;

回答by Konrad Rudolph

This actually sets two properties and is equivalent to:

这实际上设置了两个属性,相当于:

font-size: 100%;
line-height: 120%;

To quote the official documentation:

引用官方文档

The syntax of this property is based on a traditional typographical shorthand notation to set multiple properties related to fonts.

此属性的语法基于传统的印刷速记符号来设置与字体相关的多个属性。

As David M said in the comments, it mirrors the typesetting tradition of specifying typeface sizes as “x?pt on y?pt” to denote the glyph size on line height.

正如 David M 在评论中所说,它反映了将字体大小指定为“ x?pt on y?pt”的排版传统,以表示行高的字形大小。

But the example in your question is actually wrong and would be ignored by the browser: you can only combine these two properties in the fontshorthand notation, and you mustspecify at least both the font size and family. Simply writing font: 100%/120%;is therefore not enough; you could add a generic family name to make it valid though, e.g.:

但是您问题中的示例实际上是错误的并且会被浏览器忽略:您只能在font速记符号中组合这两个属性,并且您必须至少指定字体大小和系列。font: 100%/120%;因此,仅仅写作是不够的;您可以添加一个通用的姓氏以使其有效,例如:

font: 100%/120% serif;

回答by Bill the Lizard

Konrad got this one, but there are a lot of CSS shorthandproperties like this that you can use to shorten your style sheets. Some of them look a little cryptic if you're not aware of them.

Konrad 得到了这个,但是有很多像这样的CSS 速记属性可以用来缩短样式表。如果您不知道它们,其中一些看起来有点神秘。