CSS 字体简写属性


目录

    显示目录


CSS 字体属性

为了缩短代码,还可以在一个属性中指定所有单独的字体属性。

font 属性是以下属性的简写属性:

font-style
font-variant
font-weight
font-size/line-height
font-family

注意: font-sizefont-family 值是必需的。如果缺少其他值之一,则使用它们的默认值。

例子

使用 font 设置多个字体属性 一份声明:

   p.a
 {
     
 font: 20px Arial, sans-serif;
 }
 
 p.b
 {
     
 font: italic small-caps bold 12px/30px Georgia, serif;
 }

自己尝试一下 →

<!DOCTYPE html>
<html>
<head>
<style>
p.a {
  font: 20px Arial, sans-serif;
}

p.b {
  font: italic small-caps bold 12px/30px Georgia, serif;
}
</style>
</head>
<body>

<h1>The font Property</h1>

<p class="a">This is a paragraph. The font size is set to 20 pixels, and the font family is Arial.</p>

<p class="b">This is a paragraph. The font is set to italic, small-caps and bold, the font size is set to 12 pixels, the line height is set to 30 pixels, and the font family is Georgia.</p>

</body>
</html>




所有 CSS 字体属性

font

在一个声明中设置所有字体属性

font-family

指定文本的字体系列

font-size

指定文本的字体大小

font-style

指定文本的字体样式

font-variant

指定文本是否应以小型大写字体显示

font-weight

指定字体的粗细