SOuřaan Gřg
SOuřaan Gřg

Reputation: 399

Images which where added on html from css won't display when that particular css file is kept inside a folder

On my project work I have got two css file one for index-page another for home-page.I thought that I should keep those two css files on a folder so, if on coming days if i added more css files then it will be easy for me to find them all in one folder so, i did.I have one folder for images also.

My question is that when I add an image from css (background-image property) to my any page it won't display there but other images which were added from html img src=' ' property they are all displayed.

when i again placed that two css files from it's css folder to outside together with index.php,home.php then all those image which were not shown earlier by css background-image property were shown again! what may be the reason behind happening that???

Upvotes: 0

Views: 507

Answers (1)

chennighan
chennighan

Reputation: 476

I think you may have a filepath issue here, though I don't have much information to go on. If your css files are in let's say "main/css/" and you're trying to access an image in a directory above it, then you're either going to have to give the background-image src an absolute path or use ../ to break out of your current directory. Example:

if your image resides in the main folder 1 level above your css folder:

#myImage {
   background-image: src("../myImagePic.png");
}

This is probably the reason why when you add the image from your HTML file that's in the main directory it works and then in your CSS which is located inside a CSS folder inside of the main directory it doesn't work. Hopefully this helps, didn't have much to go on.

Upvotes: 2

Related Questions