英文:
Bulletproof @Font-Face Syntax
问题
我正在尝试通过FTP安装字体,但出现了错误的Bulletproof字体样式语法。请问,我做错了什么?
@font-face {
font-family: 'Brasilero2018Free';
src:
url('/themes/fonts/Brasilero2018Free.woff2') format('woff2'),
url('/themes/fonts/Brasilero2018Free.woff') format('woff'),
url('/themes/fonts/Brasilero2018Free.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}
英文:
I'm trying to install a font via FTP and there is this error of wrong Bulletproof font-face syntax. Please, what am I doing wrong?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
@font-face {
font-family: 'Brasilero2018Free';
src:
url('/themes/fonts/Brasilero2018Free.woff2') format('woff2'),
url('/themes/fonts/Brasilero2018Free.woff') format('woff'),
url('/themes/fonts/Brasilero2018Free.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}
<!-- end snippet -->
答案1
得分: 1
I've tested your @font-face
rule in css-live editor (extension).
There is a CORS issue (see the dev tools console):
> Access to font at
> 'https://www.flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff2'
> from origin 'https://flordeibez.org' has been blocked by CORS policy:
> No 'Access-Control-Allow-Origin' header is present on the requested
> resource.
Your website's primary URL is https://flordeibez.org
but your css references the www
subdomain.
Changing your font src like solved the problem in my test.
@font-face {
font-family: 'Brasilero2018Free';
src:
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff2') format('woff2'),
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff') format('woff'),
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.ttf') format('truetype');
}
Provided your css
file is in your theme folder you could use relative paths like:
@font-face {
font-family: 'Brasilero2018Free';
src:
url('../fonts/Brasilero2018Free.woff2') format('woff2'),
url('../fonts/Brasilero2018Free.woff') format('woff'),
url('../fonts/Brasilero2018Free.ttf') format('truetype');
}
If this font-family doesn't include italics or other width you should specify fonst style and weight too:
@font-face {
font-family: 'Brasilero2018Free';
src:
url('../fonts/Brasilero2018Free.woff2') format('woff2'),
url('../fonts/Brasilero2018Free.woff') format('woff'),
url('../fonts/Brasilero2018Free.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}
Keep in mind, you also need to apply the font-family to an HTML element - otherwise, the browser won't load it.
E.g. apply it to the <h1>
heading:
h1{
font-family: 'Brasilero2018Free';
font-weight: 400;
font-style: normal;
}
BTW. you can safely remove .eot (Internet Explorer only) and .svg fonts (not supported by Firefox or Chrome since years). Instead, add the woff2
version since it's the most compact format.
I also highly recommend removing the local()
rule as it can introduce issues in some browsers blocking locally installed fonts.
Issues with elementor specificity
Elementor and other page builder plugins tend to add a lot of CSS specificity to font styles.
Workaround:
Install a plugin like Custom Fonts to upload custom fonts in your admin area/media library.
Go to your theme customizer and open the Additional CSS drawer and add a custom rule using !important
to override existing styles.
h1{
font-family: 'Brasilero2018Free'!important;
font-weight: 400;
font-style: normal;
}
英文:
I've tested your @font-face
rule in css-live editor (extension).
There is a CORS issue (see the dev tools console):
> Access to font at
> 'https://www.flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff2'
> from origin 'https://flordeibez.org' has been blocked by CORS policy:
> No 'Access-Control-Allow-Origin' header is present on the requested
> resource.
Your website's primary URL is https://flordeibez.org
but your css references the www
subdomain.
Changing your font src like solved the problem in my test.
@font-face {
font-family: 'Brasilero2018Free';
src:
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff2') format('woff2'),
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.woff') format('woff'),
url('https://flordeibez.org/wp-content/themes/fonts/Brasilero2018Free.ttf') format('truetype');
}
Provided your css
file is in your theme folder you could use relative paths like:
@font-face {
font-family: 'Brasilero2018Free';
src:
url('../fonts/Brasilero2018Free.woff2') format('woff2'),
url('../fonts/Brasilero2018Free.woff') format('woff'),
url('../fonts/Brasilero2018Free.ttf') format('truetype');
}
If this font-family doesn't include italics or other width you should specify fonst style and weight too:
@font-face {
font-family: 'Brasilero2018Free';
src:
url('../fonts/Brasilero2018Free.woff2') format('woff2'),
url('../fonts/Brasilero2018Free.woff') format('woff'),
url('../fonts/Brasilero2018Free.ttf') format('truetype');
font-weight: 400;
font-style: normal;
}
Keep in mind, you also need to apply the font-family to a HTML element - otherwise the browser won't load it.
E.g. apply it to the <h1>
heading:
h1{
font-family: 'Brasilero2018Free';
font-weight: 400;
font-style: normal;
}
BTW. you can safely remove .eot (Internet Explorer only) and .svg fonts (not supported by Firefox or Chrome since years). Instead add the woff2
version since it's the most compact format.
I also highly recommend to remove the local()
rule as it can introduce issues in some browsers blocking locally installed fonts.
Issues with elementor specificity
Elementor and other page builder plugins tend to ad a lot of CSS specificity to font styles.
Workaround:
Install a plugin like Custom Fonts to upload custom fonts in your admin area/media library.
Go to your theme customizer and open the Additional CSS drawer and add a custom rule using !important
to override existing styles.
h1{
font-family: 'Brasilero2018Free'!important;
font-weight: 400;
font-style: normal;
}
答案2
得分: 0
使用以下语法:
src: url('某个网址');
src: url('另一个网址');
你只是在每一行中重新定义了字体的网址。因此,浏览器将仅使用最后一个,其他的将被丢弃。正确的基本语法是:
@font-face {
font-family: 'SomeFont';
src:
local("SomeFont"),
url('//host.tld/SomeFont.woff2') format('woff2'),
url('//host.tld/SomeFont.woff') format('woff'),
url('//host.tld/SomeFont.ttf') format('truetype');
}
如果需要满足旧版浏览器的要求,可以包括额外的字体格式。
注意:感谢 @herrstrietzel,已更正错误的 `format('ttf')` 为 `format('truetype')`。
英文:
With your syntax as:
src: url('some_url');
src: url('other_url');
you just redefine the URL for the font with every line. So browser will use only the last one, others are just discarded. The correct basic syntax is:
@font-face {
font-family: 'SomeFont';
src:
local("SomeFont"),
url('//host.tld/SomeFont.woff2') format('woff2'),
url('//host.tld/SomeFont.woff') format('woff'),
url('//host.tld/SomeFont.ttf') format('truetype');
}
You can include extra font formats if you need to satisfy old browsers.
NB: changed incorrect format('ttf')
to format('truetype')
, thanks to @herrstrietzel
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论