为了缩短代码,还可以在一个属性中指定所有单独的字体属性。
font
属性是以下属性的简写属性:
font-style
font-variant
font-weight
font-size/line-height
font-family
注意: font-size
和 font-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>
在一个声明中设置所有字体属性
指定文本的字体系列
指定文本的字体大小
指定文本的字体样式
指定文本是否应以小型大写字体显示
指定字体的粗细