简体   繁体   English

在CSS中包含多种字体的正确方法

[英]The right way to include multiple fonts in css

I don't a simple moment. 我不是一个简单的时刻。 Which way is the right way to include multiple fonts in css? 在CSS中包含多种字体的正确方法是哪一种? Here are simple examples. 这是简单的例子。

This? 这个?

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

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

or this? 或这个?

@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;
}

And why? 又为什么呢? I use the second one, because I can add font-family to BODY and just add font-style or font-weight to other classes. 我使用第二个,因为我可以将字体家族添​​加到BODY中,而只需将字体样式或字体粗细添加到其他类中。 And it works. 而且有效。

But I saw people using the first method many times. 但是我看到人们多次使用第一种方法。 But it seems to me too rude. 但是在我看来,这太不礼貌了。 Every time you need to add bold to a class you have to use "font-family: DeliciousRomanRegular, Arial, sans-serif;". 每次需要在类中添加粗体时,都必须使用“字体家族:DeliciousRomanRegular,Arial,无衬线;”。 WTF? WTF?

The second option: you use the same font name, but for each variant you intend to use, you need to specify (a) the variation and (b) the alternate resource to use as font. 第二种选择:使用相同的字体名称,但是对于要使用的每个变体,您需要指定(a)变体和(b)用作字体的替代资源。

This ensures that in your actual content CSS you can do things like: 这样可以确保在您的实际内容CSS中您可以执行以下操作:

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

p em {
  font-style: italic;
}

p strong {
  font-weight: 800;
}

And things will work correctly. 一切都会正常进行。 Contrast this to the ridiculous notion of "changing the font family just because you wanted the same font, but italic". 将此与“仅因为您想要相同的字体但斜体而更改字体系列”这一荒谬的概念相对照。 Let's not do that. 我们不要那样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM