8.6. CSS font 属性
font -- 定义字体的属性
- 取值:[ [ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family> ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
- [ [ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family> ]:字体取值
- caption | icon | menu | message-box | small-caption | status-bar:定义系统字体
- inherit:继承
- 引用网址:http://www.dreamdu.com/css/property_font/
- 初始值: 根据字体其它属性的默认值
- 继承性: 是
- 适用于: 所有元素
- font:字体.
前面的讲的五个字体属性完全可以使用font属性代替
font的取值有点复杂,取值主要分为两部分,现在举几个[ [ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family> ]取值的例子.
示例
p{font:italic small-caps bold 12px/1.2em Arial;}
定义段落的字体为斜体(font-style属性),小型的大写字母(font-variant属性),粗体(font-weight属性),12px字体大小(font-size属性),1.2倍(字体)的行高(line-height属性),Arial字体(font-family属性)
p{font:1em Arial;}
定义段落的字体为1倍字体大小(font-size属性),Arial字体(font-family属性),这是字体取值的最小形式(使用字体font属性时最少也要有font-size和font-family)
p{font:bold 1em "宋体",Arial,Times;}
定义段落的字体为粗体(font-weight属性),1倍字体大小(font-size属性),"宋体",Arial,Times字体(font-family属性)
p{font:italic 12px/2em "宋体",Arial,Times;}
定义段落的字体为斜体(font-style属性),12px字体大小(font-size属性),2倍(字体)的行高(line-height属性),"宋体",Arial,Times字体(font-family属性)
CSS font 属性示例 -- 可以尝试编辑
说明
- HTML的font标签定义了字体的样式,此标签已经被w3c抛弃
参考
From "CSS font 属性 - CSS字体 - CSS教程"