sam
sam

Reputation: 10084

does the src of a background image relate to its path from the css or the file its being used in?

When you use a background image and set the src are you making that the src from the css file the path or the source from the file that the background image will actually be active in ?

Upvotes: 0

Views: 253

Answers (3)

Blazemonger
Blazemonger

Reputation: 92913

Links in a CSS file are always relative to the location of that CSS file. This is desirable, since the CSS may be linked from any subdirectory or even from a different server.

Upvotes: 0

Sean Powell
Sean Powell

Reputation: 1437

The src attribute in HTML is relative to the rendered document. If you had a file /index.html and the img you wanted to inlude was at /img/1.png, the attribute would read src="img/1.png".

Likewise, the url attribute in CSS is relative to the CSS document. If your CSS file was at /css/styles.css the attribute would read background:url('../img/1.png').

Upvotes: 1

DickieBoy
DickieBoy

Reputation: 4956

the path from the css file is what you should use

Upvotes: 0

Related Questions