【问题标题】:Using CSS @font-face properly正确使用 CSS @font-face
【发布时间】:2014-02-21 11:07:17
【问题描述】:

您好,我有一个关于使用 CSS @font-face 创建字体系列的快速问题。

传统上,我曾经这样设置我的 CSS 字体:

@font-face {
    font-family: 'My Font Regular';
    src: url('fonts/myfont.ttf');
}
@font-face {
    font-family: 'My Font Bold';
    src: url('fonts/myfont-bold.ttf');
}
p { font-family: "My Font Regular";}
strong {font-family: "My Font Bold";}

但是我最近发现你可以这样做:

@font-face {
    font-family: 'My Font';
    src: url('fonts/myfont.ttf');
    font-style:normal;
    font-weight:normal;
}
@font-face {
    font-family: 'My Font';
    src: url('fonts/myfont-bold.ttf');
    font-style:normal;
    font-weight:bold;
}
p { 
font-family: "My Font" ; 
font-style:normal;
font-weight:normal;
}
strong { 
font-family: "My Font" ;
font-style:normal;
font-weight:bold; 
}

我的问题是,如果我使用第二种粗体技术,文本是否仍会使用自定义 .eot 呈现,或者浏览器是否会尝试在不使用实际粗体字体文件的情况下模拟它?

谢谢

【问题讨论】:

标签: css fonts


【解决方案1】:

如果您的字体文件是粗体字体,则设置font-weight: bold 是多余的,并且无需声明font-weight: normal,因为这是默认值。您还应该使用多个 .eot 文件,这样您就可以像其他人建议的那样回退其他浏览器。

【讨论】:

    【解决方案2】:

    这是我使用的一个例子:

            @font-face {
                font-family: 'Franklin Demi';
                src: url('FranklinDemi.eot'),
                     url('FranklinDemi.ttf') format('truetype'),
                     url('FranklinDemi.svg#font') format('svg');
                }
            @font-face {
                font-family: 'Franklin Heavy';
                src: url('FranklinHeavy.eot'),
                     url('FranklinHeavy.ttf') format('truetype'), 
                     url('FranklinHeavy.svg#font') format('svg');
                }
            .sidansTitel{
                font-family: 'Franklin Demi';
                font-size: 22pt;
                color: #8b9ba7;
                text-shadow: 0 1px 0 rgba(0,0,0,0.01);
                }
            .sidansTitel b{
                font-family: 'Franklin Heavy';
                font-weight: normal;
                font-style: normal;
                }
    

    同时设置font-weight: normal;font-style: normal; 使字体在ie/ff/chrome 中呈现良好,没有它在Chrome 中看起来像废话。我认为它在 Chrome 中看起来像垃圾,因为它试图将粗体字体呈现为粗体,这应该被修复。

    编辑:拼写

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-30
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2013-08-20
      • 2017-12-20
      • 1970-01-01
      相关资源
      最近更新 更多