使用CSS加载本地字体

发布于 2025-01-20 02:16:04 字数 775 浏览 5 评论 0原文

我在本地托管一个 javascript 项目并尝试使用本地字体,但它似乎未加载,这是我的 style.css 代码,ipixregular 是我尝试使用的字体,我可以知道可能是什么问题吗?我需要在html中引用它吗?谢谢

@import "@fontsource/press-start-2p/index.css";
@import "@16bits/nes.css/css/nes.min.css";

@font-face {
  font-family: 'ipixregular';
  src: url('front/ipix-webfont.eot');
  src: url('front/ipix-webfont.eot?#iefix') format('embedded-opentype'),
    url('front/ipix-webfont.woff2') format('woff2'),
    url('front/ipix-webfont.woff') format('woff'),
    url('front/ipix-webfont.ttf') format('truetype'),
    url('front/ipix-webfont.svg#ipixregular') format('svg');
  font-weight: normal;
  font-style: normal;

}

* {
  font-family: ipixregular
}

.nes-btn {
  font-family: "Press Start 2P";
}

I am hosting a javascript project on locally and trying to use the local font, but it seem not loaded, here is my style.css code, ipixregular is the font i am trying to use, may I know what might be the problem? and do I need to refere it in html? thanks

@import "@fontsource/press-start-2p/index.css";
@import "@16bits/nes.css/css/nes.min.css";

@font-face {
  font-family: 'ipixregular';
  src: url('front/ipix-webfont.eot');
  src: url('front/ipix-webfont.eot?#iefix') format('embedded-opentype'),
    url('front/ipix-webfont.woff2') format('woff2'),
    url('front/ipix-webfont.woff') format('woff'),
    url('front/ipix-webfont.ttf') format('truetype'),
    url('front/ipix-webfont.svg#ipixregular') format('svg');
  font-weight: normal;
  font-style: normal;

}

* {
  font-family: ipixregular
}

.nes-btn {
  font-family: "Press Start 2P";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌生 2025-01-27 02:16:04

@Import加载字体样式规则
@font-face加载字体

我不明白为什么有规则
字体家庭:“按下2p”;
因为那不是一个有效的字体家庭。

你可以尝试
身体 * {font-fomy:ipixregular;}

@import loads the font style rules
@font-face loads the font

I do not understand why you have the rule
font-family: "Press Start 2P";
as that is not a valid font family.

You could try
body * {font-family: ipixregular;}

萌能量女王 2025-01-27 02:16:04

我注意到您在URL中使用“前面”而不是“字体”,这是清楚的 - 这是正确的文件夹名称吗?可能只是错别字。

即,来自:url('front/ipix-webfont.eot') to:url('font/ipix-webfont.eot')

I noticed that you are using "front" instead of "font" in your URLs, to be clear - is this the right folder name? Could simply be a typo.

I.e., from: url('front/ipix-webfont.eot') to: url('font/ipix-webfont.eot')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文