| 7:44 pm on Mar 10, 2012 (gmt 0)|
its probably something to do with the URL. is the image in the same directory as the html file? that would work okay for the inline method.
but if you try it with a css file, then the way you've got it written at the moment, the image would have to be in the same directory as the css file.
or wherever it is that the image is stored
| 9:54 pm on Mar 10, 2012 (gmt 0)|
|but if you try it with a css file, then the way you've got it written at the moment, the image would have to be in the same directory as the css file. |
Other way around. Relative links in external css are treated as relative to the file that uses the css, not to the css itself.
I only know this because I've gone through the "get it wrong + test it" loop about eight times in the past year. Ahem.
Site-absolute links are guaranteed to work correctly. The drawback is that you can't test them locally except by installing a pseudo-server like MAMP or WAMP. (And then jumping through further hoops if you're testing more than one domain.)
| 11:31 pm on Mar 10, 2012 (gmt 0)|
|Other way around. Relative links in external css are treated as relative to the file that uses the css, not to the css itself. |
I must disagree. Images are relative to the CSS file, not the page.
| 12:36 am on Mar 11, 2012 (gmt 0)|
The image is in the same directory as the index file.
| 2:12 am on Mar 11, 2012 (gmt 0)|
###. You're right. Tested all three ways: online, offline, and with pseudo-server.
This makes me uneasy about the configuration of the previous 8 tests. Can we all agree that site-absolute links are safe?
| 12:06 am on Mar 13, 2012 (gmt 0)|
Does anybody have any other suggestions?
| 12:22 am on Mar 13, 2012 (gmt 0)|
To confirm: The page, the external css and the image are all three in the same directory?
| 4:45 pm on Mar 13, 2012 (gmt 0)|
|The image is in the same directory as the index file. |
But where is the CSS?
The image must be relative to the location of the CSS. So if you have
you must do this in your document,
<link rel="stylesheet" href="/css/style.css" type="text/css">
... and this in your CSS.
The leading slash means "start at the domain root." It's a good habit to form early. Note that this will NOT work if you're previewing on your local computer because your local computer is not a web server and doesn't have a "domain root" (unless you add server software to it.) Using the above directory structure, you'll have to do
<link rel="stylesheet" href="css/style.css" type="text/css">
This will work in both cases, so what's the difference? When you get into large web sites and begin URL rewriting, it will become painfully apparent that the document-relative syntax will get very difficult to maintain. IF you always start at domain root, it's one less thing to worry about.