【问题标题】:Unable to change font for web page无法更改网页字体
【发布时间】:2016-01-29 16:37:52
【问题描述】:

尝试为整个正文设置外部字体,但未发生任何更改。字体文件位于正确的位置。使用其他存在的字体进行测试,例如 Times New Roman,字体也不会改变。

我正在使用引导程序,但在引导程序之后调用我的自定义 css 文件,因此我相信它应该覆盖引导程序。我在同一个文件中有其他自定义 css 可以正确执行其他代码。为了安全起见,我用 !important 调用了 font-family,也没有任何变化。这里有什么问题。

<!-- html page to show how I place my css files. -->
<head>
    <title>A Title</title>
    <!-- Jquery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <!-- Bootstrap -->
    <link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="css/bootstrap-theme.min.css">
    <script src="js/bootstrap.min.js"></script>

    <!-- Custom Files -->
    <link type="text/css" rel="stylesheet" href="css/styles.css">
    <script src="js/scripts.js"></script>
</head>  

/*styles.css file*/

@font-face {
    font-family: "KenzoCustom";
    src: url(kenzo-regular.otf);
}

body{
    background-color: #eaeaf4;
    /*font-family: "Times New Roman", Times, serif;*/ /*No change either*/
    font-family: KenzoCustom, serif; 
}

<!-- Working Code -->
@font-face {
    font-family: KenzoCustom;
    src: url('../fonts/kenzo-regular.otf');
}

body{
    background-color: #eaeaf4;
    font-family: KenzoCustom, serif;
}

【问题讨论】:

  • kenzo .otf 文件是否与您的 .css 文件位于同一目录中?请记住,外部 .css 文件中的 urls 路径是相对于 css 文件的位置的,而不是加载 css 的 html 文件。
  • @MarcB Above way= 字体文件位于 css 文件夹中。还遵循引导字体的确切 url,并将我的改为如下: url(../fonts/kenzo-regular.otf);结果相同。它甚至不适用于 Times New Roman 等其他默认字体。
  • 然后检查浏览器的调试控制台是否有错误。可能某处有 css 语法错误,或者 css 文件一开始就没有被加载。
  • 您需要将自定义字体放在引号内!(我指的是正文选择器)
  • 这可能无关紧要,但你可以用引号 font-family: "KenzoCustom", serif; 试试。

标签: html css twitter-bootstrap fonts


【解决方案1】:

有时你必须使用父 css font-family: "KenzoCustom", serif !important;

【讨论】:

    猜你喜欢
    • 2019-11-23
    • 1970-01-01
    • 2022-06-14
    • 2016-08-09
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 2022-08-05
    • 2020-10-31
    相关资源
    最近更新 更多