Ben*_*enn 37 css fonts conventions
据我所知,如果字体包含空格,则需要使用双引号或单引号,例如:
font-family: "Times New Roman", Times;
font-family: 'Times New Roman', Times;
Run Code Online (Sandbox Code Playgroud)
但在Google字体(http://www.google.com/webfont)上,我也看到了
font-family: 'Margarine', cursive;
Run Code Online (Sandbox Code Playgroud)
有些甚至像这样使用它:
font-family: 'Margarine', 'Helvetica', arial;
Run Code Online (Sandbox Code Playgroud)
我发现这很奇怪,因为以下工作原理:
font-family: Arial, Helvetica, sans-serif;
font-family: Cambria, serif;
Run Code Online (Sandbox Code Playgroud)
那么CSS中字体名称的引用的正确用法是什么?
我刚刚了解到,引号不是必需的,而是推荐的。我们每天都在学习新东西。
您看到它们的另一个地方是在需要 url 的 css 属性中
background:url('hithere.jpg');
background:url(hithere.jpg);
Run Code Online (Sandbox Code Playgroud)
这两个语句的工作原理完全相同。字体也是如此,在这种情况下,您使用哪种类型的引用无关紧要,只要在您做事的方式上保持一致,这才是真正重要的。
font-family: Times New Roman; /* These are equivalent */
font-family: 'Times New Roman';
font-family: "Times New Roman";
font-family: Unique Ode™ Épopée; /* These are equivalent */
font-family: "Unique Ode™ Épopée";
font-family: "Answer #42" /* These are equivalent */
font-family: "Answer \23 42";
font-family: Answer \23 42;
Run Code Online (Sandbox Code Playgroud)
只要字体名称仅包含:
那么引号是可选的。单引号或双引号。忽略大小写。有一些奇怪的边缘情况:未引用的单词不能以数字、破折号或破折号开头。
font-family: "Intro Rust 2" /* Unquoted words must not start with numbers. */
font-family: "Serif"; /* For your own Serif, not the generic serif. */
font-family: "Yin/Yang"; /* Quote or code most ASCII punctuation. */
Run Code Online (Sandbox Code Playgroud)
font-family: "Initial Seals JNL" /* `initial` and `default` are reserved words. */
font-family: "Omar Serif" /* Generic names might also be reserved words? */
Run Code Online (Sandbox Code Playgroud)
font-family: monospace; /* Generic fonts must NOT be quoted. */
font-family: serif;
font-family: sans-serif;
font-family: cursive;
font-family: fantasy;
Run Code Online (Sandbox Code Playgroud)
谢谢: