Is the relative path in the CSS file relative to the CSS file?

When I refer to an image or other file in a CSS file in a relative way, is the path to the CSS file or HTML file using a CSS file?

+57
css path
Apr 27 '10 at 3:33
source share
3 answers

Yes, this is relative to .css

Here is an example layout:

 Page: page.htm ... does not matter where CSS: /resources/css/styles.css Image: /resources/images/image.jpg 

CSS in styles.css :

 div { background-image: url('../images/image.jpg'); 
+73
Apr 27
source share

Yes. This is relative to the CSS file. I will add that this also applies to the domain where the CSS file is located.

So, if CSS is referenced as:

 <link href="http://www.otherdomain.com/css/example.css" type="text/css" rel="stylesheet" /> 

and contains:

 div { background-image: url('/images/image.jpg'); 

The background will be:

http://www.otherdomain.com/images/image.jpg

+4
Jul 19 '16 at 18:39
source share

To CSS file.

+1
Apr 27
source share



All Articles