css - @font-face 仿粗体 ie7-ie8

标签 css internet-explorer-8 internet-explorer-7 font-face webfonts

我一直在 IE7-8 中使用假粗体和斜体。我已经阅读了多篇关于此的文章,但它们都针对谷歌网络字体。我自己主持。请参阅此屏幕截图示例:

enter image description here

这是我编写样式声明的方式:

@font-face{
    font-family:"myfont";
    src:url("font.eot");
    src:url("font.eot?#iefix") format("embedded-opentype"),
        url("font.woff") format("woff"),
        url("font.ttf") format("truetype"),
        url("font.svg#a89d6ad1-a04f-4a8f-b140-e55478dbea80") format("svg");
    font-weight:normal;
    font-style:normal;
}
@font-face{
    font-family:"myfont";
    src:url("bold.eot");
    src:url('bold.eot?#iefix') format('embedded-opentype'),
        url("bold.woff") format("woff"),
        url("bold.ttf") format("truetype"),
        url("bold.svg#ed104d8c-7f39-4e8b-90a9-4076be06b857") format("svg");
    font-style:normal;
    font-weight:bold;
}

它们在 IE9 和 FF/webkit 中都可以正常工作,但无论我做什么,IE7-8 都会显示假粗体。 有什么我想念的吗?

(我还在我的代码中添加了粗体斜体和斜体,但在这里省略了它们)

最佳答案

我能解决这个问题的唯一可靠方法是在 IE 中为粗体声明一个不同的@font-face 名称。保留 CSS3 解决方案(如您发布的那样),但使用不同的名称为粗体添加额外的声明。使用您的示例,它可能看起来像:

/* THESE FIRST TWO ARE LEFT THE SAME */
@font-face{
    font-family:"myfont";
    src:url("font.eot");
    src:url("font.eot?#iefix") format("embedded-opentype"),
        url("font.woff") format("woff"),
        url("font.ttf") format("truetype"),
        url("font.svg#a89d6ad1-a04f-4a8f-b140-e55478dbea80") format("svg");
    font-weight:normal;
    font-style:normal;
}
@font-face{
    font-family:"myfont";
    src:url("bold.eot");
    src:url('bold.eot?#iefix') format('embedded-opentype'),
        url("bold.woff") format("woff"),
        url("bold.ttf") format("truetype"),
        url("bold.svg#ed104d8c-7f39-4e8b-90a9-4076be06b857") format("svg");
    font-style:normal;
    font-weight:bold;
}
/* SAME AS THE ABOVE BOLD FAMILY, BUT WITH A NEW NAME AND NO font-weight */
@font-face{
    font-family:"myfont-bold";
    src:url("bold.eot");
    src:url('bold.eot?#iefix') format('embedded-opentype'),
        url("bold.woff") format("woff"),
        url("bold.ttf") format("truetype"),
        url("bold.svg#ed104d8c-7f39-4e8b-90a9-4076be06b857") format("svg");
}

这里我没有使用“font-weight: bold”,因为在这种情况下会加倍加粗字体。

然后,您将这样的内容添加到您的 IE 6-8 CSS 文件:

b, strong, h1, h2, h3, h4, h5, h6, #top_navigation {
    font-family: 'myfont-bold', 'Arial Bold', Arial, times;
    font-weight: normal !important;
}

将您想要加粗的任何内容添加到列表中,并将“Arial Bold 等”替换为其他足够接近备份的类似字体。唯一的问题是如果字体没有加载,那些东西将有一个正常的重量。我认为这是值得冒的风险。

这里有一个很好的资源来更详细地解释这个问题:Banishing faux-italic and faux-bold on CSS3 fonts in IE 8 and below

祝你好运!

关于css - @font-face 仿粗体 ie7-ie8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15661380/

相关文章:

html - 使用css使图像适合html页面的大小

html - 如何在不使用 span 的情况下将样式应用于内联元素

javascript - jQuery $_FILES 数组为空,在 IE8/9 中使用 blueimp 文件上传插件

Jquery .html() 和 .text() 删除 IE7 和 IE8 中的多余空格

html - 使用 Float 交换 HTML 元素,不适用于旧版 IE 浏览器

javascript - 在 Javascript 中更改复选框颜色

css 背景渐变不填满整个背景

javascript - 用于 IE8 的占位符代码导致下拉登录字段失去焦点

HTML5 网页在 IE8 中乱显示

css - 站点 css 与 IE 7 的兼容性不起作用