html - 使用@font-face 添加自定义字体 css NOT WORKING
问题描述
我正在尝试从 [DaFont.com (CaviarDreams)][1] 加载自定义字体,并在 css 中使用 @font-face。我使用这个:https ://www.fontsquirrel.com/tools/webfont-generator我在 css 中得到这个:
/*! Generated by Font Squirrel (https://www.fontsquirrel.com) on July 13, 2018 */
@font-face {
font-family: 'caviar';
src: url('font/caviardreams-webfont.eot');
src: url('font/caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
src: url('font/caviardreams-webfont.woff2') format('woff2'),
src: url('font/caviardreams-webfont.woff') format('woff'),
src: url('font/caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
font-weight: normal;
font-style: normal;
}
p {
font-size:40px;
font-family:caviar;
}
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>test</title>
<link rel="stylesheet" href="styles.css">
<meta charset="UTF-8">
</head>
<body>
<p>test<p>
</body>
</html>
但它不起作用!
(编辑)你能帮帮我吗?
解决方案
因此,在我的网站上对其进行测试后,我发现了一些问题:
- 您的 p 的 css 类不正确。
- 在字体 url 列表中,您有逗号分隔的半列
- 我已经尝试了与您相同的步骤,并且只获取 woff 和 woff2 文件。(所以你需要从 css 中删除 eot,svg 路径)
我的一个例子的代码:
<style>
@font-face {
font-family: 'caviar';
src: url('font/caviardreams-webfont.woff2') format('woff2');
src: url('font/caviardreams-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
p{
font-family:caviar;
font-weight:normal;
font-style:normal;
}
</style>
<div>
<p>Test</p>
</div>
希望这可以帮助,
推荐阅读
- python - PyCharm 调试器在尝试调试简单程序时“找不到空闲的套接字端口”
- python - 基于逻辑的 SQLAlchemy 过滤器
- java - 子字段上的 GraphQL 参数
- css - 仅当屏幕高度足够时 Flexbox 垂直居中
- javascript - ERROR 错误:未捕获(在承诺中):错误:调用 getActive 时必需的参数参与者 ID 为空或未定义
- neural-network - 使用 BertForTokenClassification 模型预测 NER
- android - Android Studio中SETAFFINITY ret = -1是什么意思?这是我的活动日志
- java - 基于java中的用户输入更新数据库
- javascript - -[object Object]- Google 距离矩阵上的错误 - Android 和 iOS
- ios - Hyperledger Indy iOS sdk 无法导入钱包