The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Problem inserting local image in HTML page using css? Reply To: [Solved] Problem inserting local image in HTML page using css?


Ok… here’s the problem: Your stylesheet has no idea where c:\f.jpg is. You need to use a relative file path. That is, a file path that points to the location of the image RELATIVE to the document requesting it. That is an absolute file path. The only way I can describe this is:

Imagine you’re standing on some nondescript street corner in a city you don’t know and I’m telling you how to get to your car. Now, would it do you more good for me to say “It’s at the SE corner of Washington and 4th” or would it be better for me to say “From where you’re standing, you need to head into the sunset for 200 yards?” Obviously the latter… provided you didn’t have a smartphone… which your stylesheet doesn’t.

I’m not really certain of the syntax, but you need to jump up a level in the file system or go one deeper, whatever you prefer.

Here’s your photo:


Here is your stylesheet:


Your stylesheet needs to know to look beyond the css directory it’s in and go looking up in c:\ or ‘down’ in c:\

Try this:

background-image: url('..\f.jpg');

Not sure if that’s going to work but that’s how *Nix systems do it. Here’s what our’s looks like:

background-image: url('../f.jpg');

I hope that helped. Either that or I just confused you more.

<sidetrack> It’s so weird to see a directory called c:\ and type the ‘\’ key without first pressing shift :) </sidetrack>

Edit: An absolute filepath would probably work on a *Nix system and might work on a Windows system if done correctly… I’ve just never tried because there’s no point really.