如何(以及如何不)加载使用 @font-face 的 css 文件
How to (and how not to) load a css file that uses @font-face
我正在尝试从 css 文件加载一些个人字体 (@font-face)。
如果我使用:
<link href="css/style.css" type="text/css" rel="stylesheet" media="all">
字体未加载。
但是,使用:
<style>@import url('css/style.css');</style>
他们加载!
第一种方法不应该也有效吗?那是我一直使用的...虽然这是我第一次使用@font-face。
请注意,使用第一种方法时,CSS 应用得很好。只是字体没有加载...
编辑:
我的CSS是这样开始的:
@font-face {
font-family:'MyFont-Bold';
src: url('../type/MyFont-Bold.eot');
src: url('../type/MyFont-Bold.eot?#iefix') format('embedded-opentype'),
url('../type/MyFont-Bold.woff') format('woff'),
url('../type/MyFont-Bold.ttf') format('truetype'),
url('../type/MyFont-Bold.svg#MyFont-Bold') format('svg');
font-weight: 700;
font-style: normal;
font-stretch: normal;
unicode-range: U+0020-2212;
}
创建 font.css 并在 style.css @import(font.css)
第二个问题请阅读:http://www.htmldog.com/guides/css/advanced/atrules/
我正在尝试从 css 文件加载一些个人字体 (@font-face)。
如果我使用:
<link href="css/style.css" type="text/css" rel="stylesheet" media="all">
字体未加载。
但是,使用:
<style>@import url('css/style.css');</style>
他们加载!
第一种方法不应该也有效吗?那是我一直使用的...虽然这是我第一次使用@font-face。
请注意,使用第一种方法时,CSS 应用得很好。只是字体没有加载...
编辑:
我的CSS是这样开始的:
@font-face {
font-family:'MyFont-Bold';
src: url('../type/MyFont-Bold.eot');
src: url('../type/MyFont-Bold.eot?#iefix') format('embedded-opentype'),
url('../type/MyFont-Bold.woff') format('woff'),
url('../type/MyFont-Bold.ttf') format('truetype'),
url('../type/MyFont-Bold.svg#MyFont-Bold') format('svg');
font-weight: 700;
font-style: normal;
font-stretch: normal;
unicode-range: U+0020-2212;
}
创建 font.css 并在 style.css @import(font.css)
第二个问题请阅读:http://www.htmldog.com/guides/css/advanced/atrules/