html - @font-face 背后的规则是什么?
问题描述
我正在学习 CSS,但我对 @font-face 感到困惑。
我见过很多网站在他们的 CSS 文件中使用了三到四次 @font-face,但字体粗细不同。
像下面的示例一样,创建三个具有相同名称的 @font-face。那么如果我创建一个将适用哪一个
标记并在其中使用 font-family: 'Test'。
@font-face {
font-family: 'Test';
src: url('path') format('woff2'),
url('path') format('woff'),
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'Test';
src: url('path') format('woff2'),
url('path') format('woff'),
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: 'Test';
src: url('path') format('woff2'),
url('path') format('woff'),
font-weight: 600;
font-style: normal;
}
以下考试取自 w3schools。在这里,他们使用相同的字体系列名称定义了两次 @font-face。我的问题是如何决定将哪个字体系列应用于哪个元素?
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
}
@font-face {
font-family: myFirstFont;
src: url(sansation_bold.woff);
font-weight: bold;
}
div {
font-family: myFirstFont;
}
</style>
</head>
<body>
<h1>The @font-face Rule</h1>
<div>With CSS, websites can use fonts other than the pre-selected "web-safe" fonts.</div>
</body>
</html>
解决方案
推荐阅读
- python - Python如何在关闭程序时确保文件写入完全?
- .htaccess - htacces 重定向与子域更改
- android - 如何设置第二天或两天后的闹钟
- java - 为实体列表创建 PersistentEntityResource
- java - 如何使用来自 java 的 FTP 在大型机上创建数据集
- php - 如何访问数组中的每个值?
- java - 如何使用 Mockito 和 Junit 模拟静态方法中存在的 void 方法调用?
- web - 为什么仍在使用 cookie?
- java - 模拟 @AuthenticationPrincipal 参数
- c# - 在对象初始化中填充嵌套属性 - C#