css - 使用@font-face 时字体边缘变细
问题描述
当我通过谷歌字体标签向我的网站添加字体时,我的字体显示正常。但是当我通过@font-face 将它添加为文件时,它会变薄。
这是我使用的代码:
.title {
color: white;
font-family: 'myBodoni', serif;
position: absolute;
top: 120px;
left: 200px;
font-size: 64px;
z-index: 2;
line-height: normal;
}
.img {
position: relative;
margin: 3%;
}
@font-face {
font-family: myBodoni;
src: url(bodoni-variable.ttf); //variable file downloaded directly from google fonts
}
当我添加此代码时,它可以正常工作:
CSS:
font-family: 'Bodoni Moda', serif;
html
<link href="https://fonts.googleapis.com/css2?family=Bodoni+Moda&display=swap" rel="stylesheet">
这是使用以下代码的外观
解决方案
这是因为您只添加一个@font-type
. 您需要添加@font-type
for eot
, woff2
, woff
& svg
:
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
推荐阅读
- linux - 在 linux 机器上执行许多命令
- cmake - CMake添加以“* .a”结尾的文件
- julia - 在 Julia 中保存到 pdf 文件的问题
- python - 试图列出带有特定反应表情符号的“投票最多”的消息
- javascript - 获取顶部容器组件的问题。extjs
- mysql - MySQL UNIQUE KEY 和 FOREIGN KEY 相同的列未创建
- macos - 运行“远程调试器”时出错:无法打开调试器端口(localhost:5005):java.net.ConnectException“连接被拒绝(连接被拒绝)”
- progressive-web-apps - PWA 可以在移动设备中使用外部存储和内部存储吗?
- c - 选择排序算法能否像冒泡排序一样提前终止循环?
- javascript - 如何在 Edge 中添加 polyfill 以支持 finally()?