不知道为什么字体没有显示,请帮忙。
CSS(在css文件夹中): style.css:
@font-face {
font-family: Gotham;
src: url(../fonts/gothammedium.eot);
src: local('Gotham-Medium'),
url(../fonts/Gotham-Medium.ttf) format('truetype');
}
a {
font-family:Gotham,Verdana,Arial;
}
不知道为什么字体没有显示,请帮忙。
CSS(在css文件夹中): style.css:
@font-face {
font-family: Gotham;
src: url(../fonts/gothammedium.eot);
src: local('Gotham-Medium'),
url(../fonts/Gotham-Medium.ttf) format('truetype');
}
a {
font-family:Gotham,Verdana,Arial;
}
@font-face {
font-family: Gotham;
src: url(../fonts/gothammedium.eot);
src: url(../fonts/Gotham-Medium.ttf);
}
我曾经遇到过同样的问题,我想分享我的解决方案,因为我没有看到有人专门解决这个问题。
问题是我没有使用正确的路径。我的 CSS 如下:
@font-face {
font-family: 'sonhoregular';
src: url('fonts/vtkssonho-webfont.eot');
src: url('fonts/vtkssonho-webfont.eot?') format('embedded-opentype'),
url('fonts/vtkssonho-webfont.woff2') format('woff2'),
url('fonts/vtkssonho-webfont.woff') format('woff'),
url('fonts/vtkssonho-webfont.ttf') format('truetype'),
url('fonts/vtkssonho-webfont.svg#vtks_sonhoregular') format('svg');
font-weight: normal;
font-style: normal;
路径的问题在于我从我的CSS文件中引用字体,而它在我的CSS文件夹中。 我需要先回到上一级,然后进入字体文件夹。 现在看起来是这样的,运行得很好。
@font-face {
font-family: 'sonhoregular';
src: url('../fonts/vtkssonho-webfont.eot');
src: url('../fonts/vtkssonho-webfont.eot?') format('embedded-opentype'),
url('../fonts/vtkssonho-webfont.woff2') format('woff2'),
url('../fonts/vtkssonho-webfont.woff') format('woff'),
url('../fonts/vtkssonho-webfont.ttf') format('truetype'),
url('../fonts/vtkssonho-webfont.svg#vtks_sonhoregular') format('svg');
font-weight: normal;
font-style: normal;
我希望这可以帮助某人!
另一件需要检查的事情:
对于 .otf
字体文件,请使用 format('opentype')
而不是 format('otf')
例如使用:
@font-face {
font-family: Gotham;
src: url(../fonts/Gotham-Medium.otf) format('opentype');
}
对我而言,这是GitHub Copilot的建议准确率达到95%,但错误地使用了format('otf')
,导致我花费了一个小时来调试。
您需要将字体文件名/路径用引号括起来。
例如:
url("../fonts/Gotham-Medium.ttf")
或者
url('../fonts/Gotham-Medium.ttf')
而不是
url(../fonts/Gotham-Medium.ttf)
另外,@FONT-FACE
仅适用于某些字体文件。 :o(
你可以下载字体的所有网站都没有说明哪些字体适用,哪些不适用。
最近我遇到了一个问题,问题是我的web服务器没有配置为提供woff文件。对于IIS 7,您可以选择您的站点,然后选择MIME类型图标。如果.woff不在列表中,则需要添加它。正确的值是:
File name extension: .woff
MIME type: application/font-woff
/wp-content/themes/wp-content/themes/twentysixteen/fonts/
。
使用浏览器控制台查看此错误。不确定您的问题是什么,但请尝试以下操作:
在此处检查示例,如果它们对您无效,则可能存在其他问题
编辑:
您的源代码中有许多重复声明,这样做可以解决问题吗?
@font-face { font-family: Gotham; src: url('../fonts/gothammedium.eot'); }
a { font-family:Gotham,Verdana,Arial; }