我想在pywebview应用程序中使用自定义字体,但在添加CSS之后,只使用了备用字体。字体文件位于/css/fonts目录中,但相对路径和绝对路径都不起作用。
我的CSS:
@font-face {
font-family: 'Retro Gaming';
src: url('fonts/retro_gaming.ttf') format('truetype'),
url('fonts/retro_gaming-webfont.woff2') format('woff2'),
url('fonts/retro_gaming-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'Courier New', Courier, monospace;
}
.menu {
font-family: 'Retro Gaming', Courier, monospace;
}我的HTML:
<html>
<body>
<p class="menu">This font should be Retro Gaming</p>
<p>This font should be Courier New</p>
</body>
</html>当我启动应用程序时,我看到的消息是:
127.0.0.1 - - [24/Dec/2020 18:13:11] "GET / HTTP/1.1" 200 200
127.0.0.1 - - [24/Dec/2020 18:13:11] "GET /fonts/retro_gaming.ttf HTTP/1.1" 404 42
127.0.0.1 - - [24/Dec/2020 18:13:11] "GET /fonts/retro_gaming-webfont.woff2 HTTP/1.1" 404 52
127.0.0.1 - - [24/Dec/2020 18:13:11] "GET /fonts/retro_gaming-webfont.woff HTTP/1.1" 404 51编辑:包含字体文件路径的图像:

发布于 2020-12-28 21:14:48
好了,我想通了。我将字体文件放在与html相同的目录中(在我的例子中是assets),这样就可以很好地工作。您甚至可以为其中的字体创建子目录。
编辑:另一种选择是避免在python代码中将样式加载到窗口,而直接从HTML加载样式。
发布于 2020-12-25 02:56:29
试着在你的位置文件之前添加../,如果你的html代码在另一个文件中,css也像这样的../fonts/retro_gaming.ttf,当我喜欢你的路径时,它对我起作用。
https://stackoverflow.com/questions/65442002
复制相似问题