html - 最佳实践 - @font-face 正常/粗体/粗体

标签 html css fonts

我有一个关于通过 CSS 向网页添加自定义字体的 @font-face 命令的问题。

我一直这样使用@font-face:

@font-face {
    font-family: "MyFont";
    src: url('url-to-font') [eot, woff, ttf, ...];
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "MyFont-Bold", [Fallbacks...];
    src: url('url-to-font') [eot, woff, ttf, ...];
    font-weight: bold;
    font-style: normal;
}

* {
    font-family: "MyFont", [Fallbacks...]
}

h1 {
    font-family: "MyFont-Bold", [Fallbacks...];
}

有两件事:可以使用通配符选择器 (*) 将字体应用到整个页面吗?有没有更好的方法?

是否可以省略:

font-family: "MyFont-Bold";

然后说:

font-family: "MyFont";
font-weight: bold;

如果是,这样做有什么好处吗?

非常感谢!

最佳答案

你通常会这样做:

@font-face {
    font-family: "MyFont";
    src: url('font-regular.woff'); /* note filename */
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "MyFont";
    src: url('font-bold.woff'); /* note different filename */
    font-weight: 700;
    font-style: normal;
}

h1 {
    font-family: "MyFont", [Fallbacks...];
    font-weight: 700; /* automatically picks the bold flavour now */
}

关于html - 最佳实践 - @font-face 正常/粗体/粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30265136/

相关文章:

jQuery slideDown 菜单在第二次悬停之前不起作用

css - 使 Joomla 部分菜单项钻入类别博客布局,显示问题

fonts - 谷歌网页字体渲染浏览器差异

html - 如何禁用文本区域调整大小?

html - 在 Firefox 中调整大小时图像容器宽度不会改变

html - 如何使用 CSS 拉伸(stretch)图像?

css - 数字低于html页面上的文字

jquery - CSS隐藏除指定元素之外的所有元素

jquery - 根据 HTML 文本设置宽度

css - 使用 css font-face 的自定义字体,在不同的浏览器上有所不同