- 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 - 内联块
- CSS - 下拉菜单
- CSS - 可见性
- CSS - 溢出
- CSS - 清除浮动
- CSS - 浮动
- CSS - 箭头
- CSS - 调整大小
- CSS - 引号
- CSS - 顺序
- CSS - 位置
- CSS - 连字符
- CSS - 悬停
- CSS - 显示
- CSS - 焦点
- CSS - 缩放
- CSS - 位移
- CSS - 高度
- CSS - 连字符字符
- CSS - 宽度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 导航栏
- CSS - 覆盖层
- CSS - 表单
- CSS - 对齐
- CSS - 图标
- CSS - 图片库
- CSS - 注释
- CSS - 加载器
- CSS - 属性选择器
- CSS - 组合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 计数器
- CSS - 剪裁
- CSS - 书写模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 内嵌
- CSS - 隔离
- CSS - 滚动溢出
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指针事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大块尺寸
- CSS - 最小块尺寸
- CSS - 混合模式
- CSS - 最大内联尺寸
- CSS - 最小内联尺寸
- CSS - 偏移量
- CSS - 重音颜色
- CSS - 用户选择
- CSS 高级
- CSS - 网格
- CSS - 网格布局
- CSS - Flexbox
- CSS - 可见性
- CSS - 定位
- CSS - 层
- CSS - 伪类
- CSS - 伪元素
- CSS - @规则
- CSS - 文本效果
- CSS - 分页媒体
- CSS - 打印
- CSS - 布局
- CSS - 验证
- CSS - 图片精灵
- CSS - !important
- CSS - 数据类型
- CSS3 教程
- CSS3 - 教程
- CSS - 圆角
- CSS - 边框图片
- CSS - 多背景
- CSS - 颜色
- CSS - 渐变
- CSS - 盒阴影
- CSS - 盒装饰中断
- CSS - 光标颜色
- CSS - 文本阴影
- CSS - 文本
- CSS - 2D变换
- CSS - 3D变换
- CSS - 过渡
- CSS - 动画
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按钮
- CSS - 分页
- CSS - 变量
- CSS - 媒体查询
- CSS - 函数
- CSS - 数学函数
- CSS - 遮罩
- CSS - 形状
- CSS - 图片样式
- CSS - 特效性
- CSS - 自定义属性
- CSS 响应式
- CSS RWD - 简介
- CSS RWD - 视口
- CSS RWD - 网格视图
- CSS RWD - 媒体查询
- CSS RWD - 图片
- CSS RWD - 视频
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 转换器
- CSS - 颜色选择器和动画
- CSS 资源
- CSS - 有用资源
- CSS - 讨论
CSS - @font-face规则
CSS @font-face 规则允许我们使用标准安全网页字体选项中不可用的自定义字体。我们为字体指定一个唯一名称,并提供字体文件的路径,从而在网页开发中实现更丰富的排版。
语法
@font-face {
font-properties
}
属性值
| 字体属性 | 值 | 描述 |
|---|---|---|
| font-family | 名称 | 它指定字体的名称。必填 |
| src | URL | 它指定必须从中下载字体的 URL。必填。 |
| font-stretch |
|
它指定字体的拉伸程度。可选。默认值为 normal。 |
| font-style |
|
它指定字体的样式。可选。默认值为 normal。 |
| font-weight |
|
它指定字体的粗细。可选。默认值为 normal。 |
| unicode 范围 | unicode-range | 它定义字体支持的 Unicode 字符范围。可选。默认值为 "U+0-10FFFF" |
CSS @Font Face 规则示例
以下示例解释了具有不同值的@font-face规则。
使用单个字体的字体规则
要使用自定义字体,我们使用@font-face规则。首先,提供一个标识符名称,然后提供字体文件的 url。之后,元素将能够在font-family属性中使用字体名称。这在以下示例中显示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: "Sansation Light Font";
src: url("/css/font/SansationLight.woff");
}
h1,
p {
font-family: "Sansation Light Font", serif;
}
p {
font-weight: bold;
font-style: italic;
}
</style>
</head>
<body>
<h2>
CSS @font-face rule
</h2>
<h1>
TutorialsPoint
</h1>
<p>
TutorialsPoint is an online platform offering free
and comprehensive tutorials on a wide range of topics,
including programming, web development, and
data science. It provides structured lessons,
examples, and exercises to support self-paced
learning and skill development.
</p>
</body>
</html>
使用多个字体的字体规则
要使用多个自定义字体,我们使用@font-face规则。我们分别提供标识符名称,并指定字体文件的 url。这在以下示例中显示。
示例
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: "Sansation Light Font";
src: url("/css/font/SansationLight.woff");
}
@font-face {
font-family: "Bolder Text";
src: url("/css/font/Brygada1918-Italic.ttf");
}
.top {
font-family: "Sansation Light Font", serif;
}
.bottom {
font-family: "Bolder Text", serif;
}
p {
font-weight: bold;
font-style: italic;
}
</style>
</head>
<body>
<h2>
CSS @font-face rule
</h2>
<h1 class="top">
TutorialsPoint
</h1>
<p class="top">
TutorialsPoint is an online platform offering free
and comprehensive tutorials on a wide range of topics,
including programming, web development, and
data science. It provides structured lessons,
examples, and exercises to support self-paced
learning and skill development.
</p>
<h1 class="bottom">
TutorialsPoint
</h1>
<p class="bottom">
TutorialsPoint is an online platform offering free
and comprehensive tutorials on a wide range of topics,
including programming, web development, and
data science. It provides structured lessons,
examples, and exercises to support self-paced
learning and skill development.
</p>
</body>
</html>
支持的浏览器
| 字体格式 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| TTF/OTF | 9.0* | 4.0 | 3.5 | 3.1 | 10.0 |
| WOFF | 9.0 | 5.0 | 3.6 | 5.1 | 11.1 |
| WOFF2 | 14.0 | 36.0 | 39.0 | 10.0 | 26.0 |
| SVG | 不支持 | 不支持 | 不支持 | 3.2 | 不支持 |
| EOT | 6.0 | 不支持 | 不支持 | 不支持 | 不支持 |
* 字体格式仅在设置为“可安装”时有效
css_properties_reference.htm
广告




