添加了 4 个字体文件,但只显示了 2 个样式

4 font files added but only 2 styles displayed

我正在尝试手动将自定义字体添加到我的 WP 本地主机安装中,我目前所做的是:

CSS代码

@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunrm.woff');
    font-style: normal;
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbx.woff');
    font-weight: bold;
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunti.woff');
    font-style: italic, oblique;
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbi.woff');
    font-weight: bold;
    font-style: italic, oblique;
}
body {
    font-family: "Computer Modern", serif;
}

HTML代码

This is normal text
<strong>This is bold text</strong>
<em>This is oblique text</em>
<em><strong>This is bold and oblique text</strong></em>

但结果是这样

似乎只加载了 Bold 和 Oblique,实际上是通过将 cmunti 替换为 cmunrm(Oblique with Roman)并将 cmunbi 替换为 cmunbx(Bold CSS 文件中的粗体斜线显示

这是什么原因造成的,如何解决?

在每个定义中明确使用 font-weightfont-style 是否有帮助? 。它还添加了 css,使 strong/em 显式关联到 font-weight/font-style(可能不需要)。

不知道为什么,但这解决了问题

@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunrm.woff');
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunti.woff');
    font-style: italic;
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbx.woff');
    font-weight: bold;
}
@font-face {
    font-family: "Computer Modern";
    src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbi.woff');
    font-weight: bold;
    font-style: italic;
}