Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

css

path

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

like image 408
Nathan Osman Avatar asked Apr 27 '10 03:04

Nathan Osman


People also ask

What is relative path in CSS?

When linking to files within the same project, use a relative path. The path is determined by where a file is located within the directory. So in this example, the index file is in the same folder as the css and image files.

What is a relative path relative to?

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

What is relative and absolute path in CSS?

The difference between relative and absolute paths is that when using relative paths you take as reference the current working directory while with absolute paths you refer to a certain, well known directory.

Is path relative or absolute?

A path is either relative or absolute. An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport is an absolute path. All of the information needed to locate the file is contained in the path string.


1 Answers

Yes, it's relative to the .css

Here's 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'); 
like image 113
Nick Craver Avatar answered Oct 13 '22 12:10

Nick Craver