愚蠢的 CSS 引用问题

发布于 2024-10-11 18:23:38 字数 290 浏览 13 评论 0原文

我有一个非常奇怪的问题。我一生都无法弄清楚。

我的样式表的路径(目前)是这样的:

<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 技术交流群。

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

发布评论

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

评论(5

梦晓ヶ微光ヅ倾城 2024-10-18 18:23:38

将电子表格链接到网络浏览器时会显示“从您当前位置开始查看这些文件夹”。

因此,如果您位于 /pages/home.aspx 并且您的资产文件夹位于根目录,它将找不到它,因为它会像在 /pages/assets/css/ 中一样查看它。

  • 如果没有斜杠,则从页面的当前目录开始。 (资产/css/default.css)。
  • 如果有一个斜杠,那么它从根开始。 (/assets/css/default.css)。
  • 如果它有两个点和一个斜杠,则它从父目录开始到当前目录 (../assets/css/default.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/.

  • If there is no slash then it's starting at the page's current directory. (assets/css/default.css).
  • If there is a single slash then it starts at the root. (/assets/css/default.css).
  • If it has two dots and a slash it starts at the parent directory to the current directory (../assets/css/default.css).
东风软 2024-10-18 18:23:38

也许尝试:

<link rel="stylesheet" href="/assets/css/default.css" />

Maybe try:

<link rel="stylesheet" href="/assets/css/default.css" />
并安 2024-10-18 18:23:38

因为您的路径是相对的,请尝试:

<link rel="stylesheet" href="/assets/css/default.css" />

例如,如果路径是相对的(像您的一样):

对于 url http://example.org/foo/bar.html

他会尝试加载过滤器http://example.org/foo/assets/css/default.css

Its because your path is relative, try:

<link rel="stylesheet" href="/assets/css/default.css" />

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

深空失忆 2024-10-18 18:23:38

我知道出了什么问题了。

我不知道为什么,但我刚刚刷新了 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. :)

谁的新欢旧爱 2024-10-18 18:23:38

./sample.htmlsample.html 含义相同,其当前目录
../ 在另一个描述上层目录中查找目录。

此网站中有一个关于此的完美示例

./sample.html and sample.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

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