 
- CSS 教程
- CSS - 主页
- CSS - 简介
- CSS - 语法
- CSS - 包含
- CSS - 测量单位
- CSS - 颜色
- CSS - 背景
- CSS - 字体
- CSS - 文本
- CSS - 图像
- CSS - 链接
- CSS - 表格
- CSS - 边框
- CSS - 边距
- CSS - 列表
- CSS - 填充
- CSS - 光标
- CSS - 轮廓
- CSS - 尺寸
- CSS - 滚动条
- CSS - 内联块
- CSS - 下拉菜单
- CSS - 可见性
- CSS - 溢出
- CSS-Clearfix
- CSS-浮动
- CSS - 箭头
- CSS - 调整大小
- CSS - 引号
- CSS - 顺序
- CSS - 位置
- CSS - 连字符
- CSS - 悬停
- CSS - 显示
- CSS - 焦点
- CSS - 缩放
- CSS - 翻译
- CSS - 高度
- CSS - 宽度
- CSS - 不透明度
- CSS - Z 索引
- CSS - 底部
- CSS - 导航栏
- CSS - 叠加
- CSS - 表单
- CSS - 对齐
- CSS - 图标
- CSS - 图标
- CSS - 图片库
- CSS - 注释
- CSS - 加载器
- CSS - 属性选择器
- CSS - 组合器
- CSS-根
- CSS - 盒子模型
- CSS - 计数器
- CSS - 剪辑
- CSS - 书写模式
- CSS - Unicode-bidi
- CSS 高级
- CSS-弹性盒
- CSS - 可见性
- CSS - 定位
- CSS - 层
- CSS - 伪类
- CSS - 伪元素
- CSS - @规则
- CSS - 文本效果
- CSS - 媒体类型
- CSS - 分页媒体
- CSS-听觉媒体
- CSS - 打印
- CSS - 布局
- CSS - 验证
- CSS - 图像精灵
- CSS - 重要
- CSS3 教程
- CSS3 - 教程
- CSS3 - 圆角
- CSS3 - 边框图像
- CSS3 - 多背景
- CSS3 - 颜色
- CSS3 - 渐变
- CSS3 - 阴影
- CSS3 - 文本
- CSS3 - 网页字体
- CSS3 - 二维变换
- CSS3 - 3D 变换
- CSS3 - 动画
- CSS3 - 多列
- CSS3 - 用户界面
- CSS3 - 盒子尺寸
- CSS 响应式
- CSS - 响应式网页设计
- CSS 资源
- CSS - 有用的资源
- CSS - 讨论
CSS - 字体
本章教您如何设置 HTML 元素中可用的内容字体。您可以设置元素的以下字体属性 -
- font -family属性用于更改字体的外观。 
- font-style属性用于使字体变为斜体或斜体。 
- font -variant属性用于创建小型大写字母效果。 
- font -weight属性用于增加或减少字体的粗细程度。 
- font-size属性用于增大或减小字体的大小。 
- 字体属性用作指定许多其他字体属性的简写。 
设置字体系列
以下示例演示了如何设置元素的字体系列。可能的值可以是任何字体系列名称。
<html>
   <head>
   </head>
   <body>
      <p style = "font-family:georgia,garamond,serif;">
         This text is rendered in either georgia, garamond, or the 
         default serif font depending on which font  you have at your system.
      </p>
   </body>
</html>
 
这将产生以下结果 -
设置字体样式
以下示例演示了如何设置元素的字体样式。可能的值为正常、斜体和倾斜。
<html>
   <head>
   </head>
   <body>
      <p style = "font-style:italic;">
         This text will be rendered in italic style
      </p>
   </body>
</html> 
 
这将产生以下结果 -
设置字体变体
以下示例演示如何设置元素的字体变体。可能的值为正常值和小型大写字母。
<html>
   <head>
   </head>
   <body>
      <p style = "font-variant:small-caps;">
         This text will be rendered as small caps
      </p>
   </body>
</html> 
 
这将产生以下结果 -
设置字体粗细
以下示例演示了如何设置元素的字体粗细。font-weight 属性提供指定字体粗细程度的功能。可能的值可以是normal、bold、bolder、lighter、100、200、300、400、500、600、700、800、900。
<html>
   <head>
   </head>
   <body>
      <p style = "font-weight:bold;">
         This font is bold.
      </p>
      
      <p style = "font-weight:bolder;">
         This font is bolder.
      </p>
      
      <p style = "font-weight:500;">
         This font is 500 weight.
      </p>
   </body>
</html> 
 
这将产生以下结果 -
设置字体大小
以下示例演示了如何设置元素的字体大小。font-size 属性用于控制字体的大小。可能的值可以是xx-small、x-small、small、medium、large、x-large、xx-large、更小、更大、以像素为单位或以 % 为单位的大小。
<html>
   <head>
   </head>
   <body>
      <p style = "font-size:20px;">
         This font size is 20 pixels
      </p>
      
      <p style = "font-size:small;">
         This font size is small
      </p>
      
      <p style = "font-size:large;">
         This font size is large
      </p>
   </body>
</html> 
 
这将产生以下结果 -
设置字体大小调整
下面的例子演示了如何设置元素的字体大小调整。此属性使您能够调整 x 高度以使字体更清晰。可能的值可以是任何数字。
<html>
   <head>
   </head>
   <body>
      <p style = "font-size-adjust:0.61;">
         This text is using a font-size-adjust value.
      </p>
   </body>
</html> 
 
这将产生以下结果 -
设置字体拉伸
以下示例演示如何设置元素的字体拉伸。此属性依赖于用户的计算机是否具有所使用字体的扩展或压缩版本。
可能的值可以是正常、更宽、更窄、超压缩、超压缩、压缩、半压缩、半扩展、扩展、额外扩展、超扩展。
<html>
   <head>
   </head>
   <body>
      <p style = "font-stretch:ultra-expanded;">
         If this doesn't appear to work, it is likely that your computer 
         doesn't have a <br>condensed or expanded version of the font being used.
      </p>
   </body>
</html> 
 
这将产生以下结果 -
速记属性
您可以使用字体属性一次设置所有字体属性。例如 -
<html>
   <head>
   </head>
   <body>
      <p style = "font:italic small-caps bold 15px georgia;">
         Applying all the properties on the text at once.
      </p>
   </body>
</html>
 
这将产生以下结果 -