【发布时间】:2018-09-21 15:34:04
【问题描述】:
我一定遗漏了一些东西,css 内部文件链接是否与 css 文件相关?搜索并且到目前为止每个来源都说是,但我的文件似乎不想加载字体(fontawesome)。 index.html 文件正确加载并显示字体,因此我知道它正在工作;但是,加载 css 相关文件的 myfile.html 页面不起作用。为了使 myfile.html 工作,我必须更改 css 文件以加载相对于 myfile.html 页面(或者看起来如此)所以 ../fonts/ 但随后会破坏 index.html 页面。
由于事情的托管和完成方式,我必须保持一切相对,否则我只会使用/fonts/,但目前这不是一个选项。
为了保持简短,我只是列出了所列示例所需的 fontawesome 部分
可能遗漏了一些简单的东西,但我提取的所有参考资料都说它应该相对于 .css 文件加载。
这是文件夹/文件结构
- home
- inc
myfile.html
- fontawesome
fontawesome.min.css
- fonts
index.html
---- index.html ----
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="fontawesome/fontawesome.min.css" rel="stylesheet" type="text/css">
<title>Home Page</title>
</head>
<body>
<div><i class="fas fa-bars"></i> fun stuff here</div>
</body>
</html>
---- myfile.html ----
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../fontawesome/fontawesome.min.css" rel="stylesheet" type="text/css">
<title>myfile</title>
</head>
<body>
<div><i class="fas fa-bars"></i> fun stuff here</div>
</body>
</html>
---- fontawesome.min.css ----
.fa,.fab,.fal,.far,.fas{
-moz-osx-font-smoothing:grayscale;
-webkit-font-smoothing:antialiased;
display:inline-block;
font-style:normal;
font-variant:normal;
text-rendering:auto;
line-height:1
}
.fas.fa-pull-left{
margin-right:.3em
}
.fa.fa-pull-right,.fab.fa-pull-right,.fal.fa-pull-right,.far.fa-pull-right,.fas.fa-pull-right{
margin-left:.3em
}
@font-face{
font-family:"Font Awesome 5 Free";
font-style:normal;
font-weight:400;
src:url(fonts/fa-regular-400.eot);
src:url(fonts/fa-regular-400.eot?#iefix) format("embedded-opentype"),
url(fonts/fa-regular-400.woff2) format("woff2"),
url(fonts/fa-regular-400.woff) format("woff"),
url(fonts/fa-regular-400.ttf) format("truetype"),
url(fonts/fa-regular-400.svg#fontawesome) format("svg")
}
@font-face{
font-family:"Font Awesome 5 Free";
font-style:normal;
font-weight:900;
src:url(fonts/fa-solid-900.eot);
src:url(fonts/fa-solid-900.eot?#iefix) format("embedded-opentype"),
url(fonts/fa-solid-900.woff2) format("woff2"),
url(fonts/fa-solid-900.woff) format("woff"),
url(fonts/fa-solid-900.ttf) format("truetype"),
url(fonts/fa-solid-900.svg#fontawesome) format("svg")}
.fa,.far,.fas{
font-family:"Font Awesome 5 Free"
}
.fa,.fas{
font-weight:900
}
【问题讨论】:
-
在浏览器中使用 devtools(网络)并检查每个请求的去向。
-
这似乎是 Firefox 的问题(?),chrome 和 IE 工作正常。我用devtools加载它,网络是空的。
标签: html css relative-path