繁体   English   中英

字体未加载到我的HTML页面

[英]The font not loaded to my html page

我的CSS文件中有此代码。

style.css

@font-face {
  font-family: "KTishk";
  src: url('../fonts/KTishk.ttf');
  }

这是我网页的结构

    • index.html
    • 的CSS
      • style.css
    • 的字体
      • Tishk.ttf
    • 子文件夹
      • test.html

我的问题 :在index.html页中,CSS和字体可以正确加载并正常工作,但是在test.html (位于子文件夹目录中)中,CSS可以加载但字体没有加载并且没有应用。

用于加载样式表的代码:

index.html

<link rel="stylesheet" href="css/style.css?version=2" >

test.html 

<link rel="stylesheet" href="../css/style.css?version=2" >

做这个

@font-face {
  font-family: Griffy;
  src: url(Griffy-Regular.ttf);
  font-style: italic;
}
body {
  font-family: 'Griffy', cursive;
}

您还需要指定bold,italic等作为参考, beautiful-fonts-with-font-facew3-font-resource

您应该使用asbolute路径(以/开头)。 在您的情况下,这应该起作用:

@font-face {
  font-family: "KTishk";
  src: url('/fonts/KTishk.ttf');
}

检查此页面: https : //css-tricks.com/quick-reminder-about-file-paths/

暂无
暂无

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

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