0

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?

5 Answers5

2

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).
Kris
  • 1,789
  • 3
  • 18
  • 27
1

Maybe try:

<link rel="stylesheet" href="/assets/css/default.css" />
Trufa
  • 39,971
  • 43
  • 126
  • 190
1

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

Hannes
  • 8,147
  • 4
  • 33
  • 51
0

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

nadir.shpz
  • 124
  • 1
  • 13
  • 1
    There's an (almost 3 years old) answer already that points out that `../` gets you the parent directory to the current one, not the root directory. – Dennis Meng Dec 31 '13 at 16:45
  • @DennisMeng I faced this problem few minutes ago and fixed by trying one by one. And './' directs you to current directory. just a minute check [this](http://stackoverflow.com/questions/7591240/what-does-dot-slash-refer-to-in-terms-of-an-html-file-path-location) SO discussion and shame on yourself – nadir.shpz Dec 31 '13 at 17:22
  • Yeah, I just read the discussion you linked; it reiterates that `..` goes up a directory, which means it goes to the parent directory, not the root directory. – Dennis Meng Dec 31 '13 at 17:39
  • @DennisMeng look man, did you read `but in /css/style.css ./ is the css folder.` do you understand that this ccs folder means current directory that css in. So, go to css file and set a link with `../images/sample.png` and where does it look for this file in your project, in current or root ? – nadir.shpz Jan 01 '14 at 07:16
  • I never said anything about `./`; all I've said is related to `../`. As mentioned in the link you gave (both in the question itself and in an answer), `../` goes up one level to the *parent* directory. I never said it goes to the *current* directory. – Dennis Meng Jan 01 '14 at 07:23
  • @DennisMeng actually I got that there is a misunderstanding in my side, that I mention the same point but explained by not choosing correct words, fixed it. – nadir.shpz Jan 01 '14 at 21:57
  • @DennisMeng and also, there is no rule not to answer if question asked 3 years ago, of course I saw it but trying to share some infos – nadir.shpz Jan 01 '14 at 22:03
  • Yep, looks fine. What I meant with the first comment was that it might be good to add a little something that wasn't already covered in another answer (though at a quick glance, it *does* look like no one else mentioned `./`, so looks like you're fine). – Dennis Meng Jan 01 '14 at 22:46
0

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

  • "It never wants to work if the stylesheet is any more than 1 directory deep." guessing from that your problem was the relative thingy :) Well in any case, accept an answer so we can all go home :D – Hannes Jan 14 '11 at 17:55
  • I can't; It wants me to wait three more minutes. –  Jan 14 '11 at 17:56