我正在使用Font Squirrel将我的字体转换为可用的web版本。我不想将每个重量分别转换并包含在我的css中(所有这些调用都会增加大量的膨胀)。
有没有一种方法将多个字重打包成一个字体,使用font-weight属性来正确调用正确的字符?
试图避免伪粗体和伪斜体问题。
有没有一种方法将多个字重打包成一个字体,使用font-weight属性来正确调用正确的字符?
试图避免伪粗体和伪斜体问题。
在您的@font-face
调用中,相应地设置font-weight
和font-style
属性(而不是FontSquirrel的默认输出,其中它们全部设置为normal
,并具有每个重量/样式的单独名称),并将它们全部命名为同一字体。
这是我去年建立的一个网站的示例:
@font-face {
font-family: 'CartoGothic';
src: url('library/fonts/CartoGothicStd-Book-webfont.eot');
src: url('library/fonts/CartoGothicStd-Book-webfont.eot?#iefix') format('embedded-opentype'),
url('library/fonts/CartoGothicStd-Book-webfont.woff') format('woff'),
url('library/fonts/CartoGothicStd-Book-webfont.ttf') format('truetype'),
url('library/fonts/CartoGothicStd-Book-webfont.svg#CartoGothicStdBook') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'CartoGothic';
src: url('library/fonts/CartoGothicStd-Bold-webfont.eot');
src: url('library/fonts/CartoGothicStd-Bold-webfont.eot?#iefix') format('embedded-opentype'),
url('library/fonts/CartoGothicStd-Bold-webfont.woff') format('woff'),
url('library/fonts/CartoGothicStd-Bold-webfont.ttf') format('truetype'),
url('library/fonts/CartoGothicStd-Bold-webfont.svg#CartoGothicStdBold') format('svg');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'CartoGothic';
src: url('library/fonts/CartoGothicStd-Italic-webfont.eot');
src: url('library/fonts/CartoGothicStd-Italic-webfont.eot?#iefix') format('embedded-opentype'),
url('library/fonts/CartoGothicStd-Italic-webfont.woff') format('woff'),
url('library/fonts/CartoGothicStd-Italic-webfont.ttf') format('truetype'),
url('library/fonts/CartoGothicStd-Italic-webfont.svg#CartoGothicStdItalic') format('svg');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'CartoGothic';
src: url('library/fonts/CartoGothicStd-BoldItalic-webfont.eot');
src: url('library/fonts/CartoGothicStd-BoldItalic-webfont.eot?#iefix') format('embedded-opentype'),
url('library/fonts/CartoGothicStd-BoldItalic-webfont.woff') format('woff'),
url('library/fonts/CartoGothicStd-BoldItalic-webfont.ttf') format('truetype'),
url('library/fonts/CartoGothicStd-BoldItalic-webfont.svg#CartoGothicStdBoldItalic') format('svg');
font-weight: bold;
font-style: italic;
}
注意,FontSquirrel 没有自动按此方式生成代码的原因是,一些旧浏览器/用户代理不支持在 @font-face 声明中使用 font-weight 和 font-style 属性,因此更具向后兼容性的方法是为每个字重和样式命名不同的字体(例如 CartoGothicRegular、CartoGothicBold、CartoGothicItalic、CartoGothicBoldItalic 等)。这里是对Ennui答案的支持:
@font-face {
font-family: 'Your Font';
src: url('fonts/SF Your Font.eot');
src: local('☺'), url('fonts/SF Your Font.woff') format('woff'), url('fonts/SF Your Font.ttf') format('truetype'), url('fonts/SF Your Font.svg') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Your Font';
src: url('fonts/SF Your Font Bold.eot');
src: local('☺'), url('fonts/SF Your Font Bold.woff') format('woff'), url('fonts/SF Your Font Bold.ttf') format('truetype'), url('fonts/SF Your Font Bold.svg') format('svg');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'Your Font';
src: url('fonts/SF Your Font Italic.eot');
src: local('☺'), url('fonts/SF Your Font Italic.woff') format('woff'), url('fonts/SF Your Font Italic.ttf') format('truetype'), url('fonts/SF Your Font Italic.svg') format('svg');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'Your Font';
src: url('fonts/SF Your Font Bold Italic.eot');
src: local('☺'), url('fonts/SF Your Font Bold Italic.woff') format('woff'), url('fonts/SF Your Font Bold Italic.ttf') format('truetype'), url('fonts/SF Your Font Bold Italic.svg') format('svg');
font-weight: bold;
font-style: italic;
}
创建单独的字体是不可避免的,但使用font-weight
和font-style
属性可以减少调用。只需声明一次font-family
。