Hello guys,

I'm making a website and i have a problem with the images from the css file.
I'm using subfolders for the website (www.domain.com/category) and i'm using css sprites for the images and i'm having problems including the images. i don't want to use absolute paths. The path to the images is like this (images/logo.png) and when i navigate to www.domain.com/category the images can't be seen.

4 Years
Discussion Span
Last Post by pixelsoul

If you're just using a single CSS file (or even a bunch, but all the in the same directory) and all images are in the same directory, using relative paths should be easy. As JorgeM said, use a forward slash at the beginning of your path to start at the root. Otherwise if that's too far away, you could use "../" to go up levels.

Votes + Comments
The correct answer, but he just doesn't understand

i know abou ../ or even ./../ but my problem is that i have 1 css file in css/style.css and i need to use it on index(root folder), index(root/sub1), index(root/sub2/sub-sub) and if do ../ will work only for 1 of this types, can i think i'll use home/user/www/images/logo is thins the correct approch for me. I think this is the last resort, the down side is i cant view the website on localhost...


That sounds more like an issue with the path to your CSS file, not your images.
You still shouldn't be having a problem with including your CSS. As JorgeM suggested previously, you can make the path relative to your document root by starting with a forward slash. Have you tried this?

<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />

If your css FOLDER is in your document root (home/user/www/) then this should work.


It is all in relation to where your CSS file is to your images. If your CSS and Images folders are under the root of your site, and you want to reference an image from the Images folder in your css file, then you should only have to do ../images/image.jpg.

The path that will be different is the link to the style sheet on all of your files. Also, I am betting that "home/user/www/" won't work in the path of the image since no visitor has access to anything above your root which should be www.

Edited by pixelsoul

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.