ivyrose
ivyrose

Reputation: 27

Clarification on HTML file paths

I am new to this. I have a funny situation where my file paths for images show up fine for the images linked in my index.html file, but not for the background image that I have set in my css file.

Images for both files are located in the same place. Root directory< img folder< images are here.

My image code in the HTML looks like this: <src="img/imgname.extension" alt="something" /> My image code for the background in the css looks like this: background: url("img/imgname.extension")

Is this file path correct?

Upvotes: 0

Views: 73

Answers (1)

Quentin
Quentin

Reputation: 943615

URLs for CSS files are relative to the URL of the CSS file, not the HTML document that loads the CSS file.

Presumably, your CSS file is at (root)/css/style.css or similar, so you could need to go up a level (../) to get to the root before going down into the img directory.

Upvotes: 1

Related Questions