我正在使用同一个家族的多种网络字体,以避免浏览器以假粗体和呈现faux-italics
。在声明选择器时,我为所有font-family
属性设置了相同的名称,并在使用font-weight
和font-style
进行区分。
这是我用于Exo的示例。
@font-face {
font-family: "exo";
src: url("../fonts/exo/exo-regular.eot");
src: url("../fonts/exo/exo-regular.eot?#iefix") format("embedded-opentype"),
url("../fonts/exo/exo-regular.woff2") format("woff2"),
url("../fonts/exo/exo-regular.woff") format("woff"),
url("../fonts/exo/exo-regular.ttf") format("truetype"),
url("../fonts/exo/exo-regular.svg#exo") format("svg");
font-weight: "normal";
font-style: "normal";
}
@font-face {
font-family: "exo";
src: url("../fonts/exo/exo-bold.eot");
src: url("../fonts/exo/exo-bold.eot?#iefix") format("embedded-opentype"),
url("../fonts/exo/exo-bold.woff2") format("woff2"),
url("../fonts/exo/exo-bold.woff") format("woff"),
url("../fonts/exo/exo-bold.ttf") format("truetype"),
url("../fonts/exo/exo-bold.svg#exo") format("svg");
font-weight: "bold";
font-style: "normal";
}
p {
font-family: "exo", sans-serif;
}
我已经确认段落标记不会从另一个选择器继承字体粗细。
从上述CSS中,我期望<p/>
标签具有正常的字体粗细。而是所有的实例<p/>
均为粗体。检查浏览器检查器的字体粗细时,它会显示为“正常”。
我还使用带有Web字体的Roboto来处理所有常规,粗体,斜体和bold-italics
。@font-face
列出的最后一个选择器是默认使用的选择器。
我已经看到了使用不同的字体系列名称(例如font-family: "exo-bold"
)来实现此方法的不同方法,但我不必这样做。我的目标是:
exo-regular.woff
,exo-bold.woff
)。font-family
对于相同字体的所有粗细和样式变体使用相同的名称。font-weight
和font-style
属性以标识这些变体。<strong>
。好像我以前已经做过,而且奏效了。谁能发现我的方法中存在错误?
您的font-weight
和font-style
规则中不应使用引号。这将起作用:
@font-face {
font-family: "exo";
/* files for normal weight */
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "exo";
/* files for bold weight */
font-weight: bold;
font-style: normal;
}
实际上,在CSS中,仅在字体名称或文件名中包含空格或其他保留字符时才需要使用引号。所以这应该工作:
<!-- language: lang-css -->
@font-face {
font-family: exo;
src: url(../fonts/exo/exo-regular.eot);
src: url(../fonts/exo/exo-regular.eot?#iefix) format(embedded-opentype),
url(../fonts/exo/exo-regular.woff2) format(woff2),
url(../fonts/exo/exo-regular.woff) format(woff),
url(../fonts/exo/exo-regular.ttf) format(truetype),
url(../fonts/exo/exo-regular.svg#exo) format(svg);
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: exo;
src: url(../fonts/exo/exo-bold.eot);
src: url(../fonts/exo/exo-bold.eot?#iefix) format(embedded-opentype),
url(../fonts/exo/exo-bold.woff2) format(woff2),
url(../fonts/exo/exo-bold.woff) format(woff),
url(../fonts/exo/exo-bold.ttf) format(truetype),
url(../fonts/exo/exo-bold.svg#exo) format(svg);
font-weight: bold;
font-style: normal;
}
p {
font-family: exo, sans-serif;
}
我个人仅在CSS无法使用时使用引号。
但是您永远不要引用普通的CSS术语,因为它们会停止工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句