【问题标题】:4 font files added but only 2 styles displayed添加了 4 个字体文件,但只显示了 2 个样式
【发布时间】:2020-01-15 23:56:06
【问题描述】:

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

  • 从 fontsquirrel 以.woff 格式下载字体(Computer Modern)
  • 获取所需的 4 个文件 (Serif):罗马 (cmunrm)、粗体 (cmunbx)、斜体 (cmunti)、斜体粗体 (cmunbi)
  • 将4个文件放入文件夹C:\xampp\htdocs\sitename\wp-includes\fonts\latex
  • style.css中写入以下内容

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;
}
  • 在 WP 编辑器中编写以下内容

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,实际上通过在 CSS 文件中将 cmunti 替换为 cmunrm(Oblique 与 Roman)和 cmunbicmunbx(Bold Oblique 与 Bold)替换这是显示

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

【问题讨论】:

    标签: css wordpress fonts


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      在每个定义中明确使用font-weightfont-style 是否有帮助? That's what this answer does。它还添加了使strong/em 明确关联到font-weight/font-style 的css(可能不需要)。

      【讨论】:

      • 我尝试了font-weightfont-style 的所有组合,直到找到正确的组合,请参阅我的答案
      • 啊,可能是oblique。很高兴你明白了!
      猜你喜欢
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-10
      • 1970-01-01
      • 2021-10-20
      相关资源
      最近更新 更多