首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在一个字体文件中为多个字体定义font-face?

问如何在一个字体文件中为多个字体定义font-face?
EN

Stack Overflow用户
提问于 2012-11-06 20:53:55
回答 2查看 2.9K关注 0票数 2

我在一个单一的字体文件中有一个字体系列,具有多种粗细和样式(常规,粗体,斜体,粗体斜体),并希望使用@ font -face标签定义字体。我该怎么做呢?

如果我这样做:

代码语言:javascript
复制
@font-face {
    font-family: 'Font Regular';
    src: url('font.eot');
    src: url('font.eot?#iefix') format('embedded-opentype'),
       url('font.woff') format('woff'),
       url('font.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}

@font-face {
font-family: 'Font Bold';
    src: url('font.eot');
    src: url('font.eot?#iefix') format('embedded-opentype'),
        url('font.woff') format('woff'),
        url('font.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

..。它以普通字体显示Regular和Bold。

如果我为h1、h2、h3等设置了font-weight:粗体,它会将这些元素显示为电子粗体。如何从一个字体文件中提取多个字体?

EN

回答 2

Stack Overflow用户

发布于 2012-11-07 01:37:24

如果你确实将所有的粗细和样式都嵌入到一个字体文件中,那么我相信你唯一的解决方案就是将这些定义分离到多个文件中(不确定这里面会涉及到什么),因为据我所知,@font-face只能将它们作为单独的文件来处理。

通常,开放的可在web上使用的字体系列将粗细和样式分解到单独的文件中,而不是包含在单个文件中。您可以搜索以确保您的字体尚未作为单独的文件提供。我所知道的所有示例都将它们作为单独的文件。这样,不同的文件可以用于不同的权重/样式,但使用相同的font-family名称,如下所示:

代码语言:javascript
复制
@font-face {
    font-family: 'myFont';
    src: url('font-REGULAR.eot');
    src: url('font-REGULAR.eot?#iefix') format('embedded-opentype'),
       url('font-REGULAR.woff') format('woff'),
       url('font-REGULAR.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'myFont';
    src: url('font-BOLD.eot');
    src: url('font-BOLD.eot?#iefix') format('embedded-opentype'),
        url('font-BOLD.woff') format('woff'),
        url('font-BOLD.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: 'myFont';
    src: url('font-ITALIC.eot');
    src: url('font-ITALIC.eot?#iefix') format('embedded-opentype'),
       url('font-ITALIC.woff') format('woff'),
       url('font-ITALIC.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
}

@font-face {
    font-family: 'myFont';
    src: url('font-BOLDITALIC.eot');
    src: url('font-BOLDITALIC.eot?#iefix') format('embedded-opentype'),
        url('font-BOLDITALIC.woff') format('woff'),
        url('font-BOLDITALIC.ttf') format('truetype');
    font-weight: bold;
    font-style: italic;
}
票数 2
EN

Stack Overflow用户

发布于 2015-02-24 21:54:23

使用这个简单的工具,您可以将单个字体文件拆分为多个文件。适用于Mac和Windows。

http://peter.upfold.org.uk/projects/dfontsplitter

希望这能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13251503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档