愚蠢的 CSS 引用问题
我有一个非常奇怪的问题。我一生都无法弄清楚。
我的样式表的路径(目前)是这样的:
<link rel="stylesheet" href="assets/css/default.css" />
但是,为什么它不加载样式表?
当我将样式表移动到与 index.html 页面相同的位置,然后更改对它的引用以指向根目录时,它会再次起作用吗?
如果样式表深度超过 1 个目录,它永远不会起作用。
这是正常的吗?或者它仍然有效吗?
I am having a very weird problem. I cannot for the life of me figure it out.
The path for my stylesheet (at the moment), is this:
<link rel="stylesheet" href="assets/css/default.css" />
But, why does it not load the stylesheet?
When I move the stylesheet into the same location as the index.html page, and then change the references to it to point to the root dir, it works again?
It never wants to work if the stylesheet is any more than 1 directory deep.
Is this normal? Or should it still work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将电子表格链接到网络浏览器时会显示“从您当前位置开始查看这些文件夹”。
因此,如果您位于 /pages/home.aspx 并且您的资产文件夹位于根目录,它将找不到它,因为它会像在 /pages/assets/css/ 中一样查看它。
Linking the spreadsheet as you have it says to the web browser "look at these folders starting at your CURRENT location".
So if you're at /pages/home.aspx and your assets folder is at the root, it won't find it because it'll be looking at it as if it were in /pages/assets/css/.
也许尝试:
Maybe try:
因为您的路径是相对的,请尝试:
例如,如果路径是相对的(像您的一样):
对于 url
http://example.org/foo/bar.html
他会尝试加载过滤器
http://example.org/foo/assets/css/default.css
Its because your path is relative, try:
for example, if the path is relative (like yours):
for the url
http://example.org/foo/bar.html
He would try to load the filte
http://example.org/foo/assets/css/default.css
我知道出了什么问题了。
我不知道为什么,但我刚刚刷新了 FTP 客户端上的目录,资产文件夹没有上传(但它说传输成功。)
我重新上传了资产文件夹,现在它按预期工作。
聚苯乙烯
感谢大家用相对路径纠正我的错误。 :)
I figured out what was wrong.
I don't know why, but I just refreshed the directory on my FTP Client, and the assets folder wasn't uploaded (but it said transfer was successful.)
I re-uploaded the assets folder, and it is now working as expected.
P.S.
Thanks all for correcting my mistake with the relative path. :)
./sample.html
和sample.html
含义相同,其当前目录../
在另一个描述上层目录中查找父目录。此网站中有一个关于此的完美示例
./sample.html
andsample.html
are has same meaning, its current directory../
looks for parent directory, in another description one upper directory.there is a perfect example in this site about this