开发者

Silly CSS ref problem

开发者 https://www.devze.com 2023-02-04 14:58 出处:网络
I am having a very weird problem. I cannot fo开发者_StackOverflow社区r the life of me figure it out.

I am having a very weird problem. I cannot fo开发者_StackOverflow社区r 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?


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).


Maybe try:

<link rel="stylesheet" href="/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


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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号