Jump to content

[SOLVED] CSS image replacement/img source question


Derleek

Recommended Posts

So i have a question about CSS images and the url('img/location') command.

 

Ok lets say we have a directory 'root'.  Now in the root directory we have a folder called 'css' with a style.css file, a folder 'images' (duh, with all the images in it  :P), and an index.html file.

 

So we have:

root/index.html

root/images/img.jpg

root/css/style.css

 

In order to use an image as a background for <div id='image'></div> in the background: url('img/directory') command, does the syntax go

url('root/images/img.jpg')

or

url('images/img.jpg')

Link to comment
Share on other sites

I usually do my URLs relative to the root. This means you start with a forward slash, then put the path down to the file. So I would use

 

url(/root/images/img.jpg)

 

In this way it doesn't matter where the filesreside, as the target file is always found from the root. So you can move your CSS wherever you want and it should still work. (note: test this, don't take me at my word.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.