html - css中包含多种字体的正确方法

标签 html css fonts font-face

我不简单。哪种方式是在 css 中包含多种字体的正确方式?这里有一些简单的例子。

这个?

@font-face {
font-family: DeliciousRomanRegular;
src: url(/Delicious-Roman-R.otf);
}

@font-face {
font-family: DeliciousRomanBold;
src: url(/Delicious-Roman-B.otf);
}

还是这个?

@font-face {
font-family: Roman;
src: url(/Delicious-Roman-R.otf);
font-style: normal;
font-weight: normal;
}

@font-face {
font-family: Roman;
src: url(/Delicious-Roman-B.otf);
font-style: normal;
font-weight: bold;
}

为什么? 我使用第二个,因为我可以将 font-family 添加到 BODY,而只需将 font-style 或 font-weight 添加到其他类。并且有效。

但是我看到很多人使用第一种方法。但在我看来太粗鲁了。 每次需要为类添加粗体时,都必须使用“font-family: DeliciousRomanRegular, Arial, sans-serif;”。什么鬼?

最佳答案

第二个选项:您使用相同的字体名称,但对于您打算使用的每个变体,您需要指定 (a) 变体和 (b) 用作字体的替代资源。

这确保在您的实际内容 CSS 中您可以执行以下操作:

p {
  font-family: Roman;
  font-style: regular;
  font-weight: 400;
}

p em {
  font-style: italic;
}

p strong {
  font-weight: 800;
}

一切都会正常进行。将此与“改变字体系列只是因为你想要相同的字体,但斜体”的荒谬概念形成对比。我们不要那样做。

关于html - css中包含多种字体的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30521623/

相关文章:

html - CSS:格式化布局的最佳方式

html - Canvas contenteditable 不工作

html - 我如何在我的网站上操纵这个元素

html - -webkit-border-radius 看起来很难看

css - 为什么浏览器上显示的字体与我的可视化 Web 开发人员不同?

css - 尝试过 Google 字体 - 现在链接不起作用

unix - 如果您可以像使用 CSS 一样动态更改终端中的字体

html - 停止 CSS3 列分解段落

html - 将 "Login link"从 Bootstrap 导航栏移到右侧

css - 在 :active without moving surrounding elements 上变大的元素