简体   繁体   中英

File layout and link to assets?

Here is my sites folder structure:

index.html
assets>img>all my images are here
css>my css files here

In my index file I reference the images 'assets/img/myimage.jpg'

In the CSS I try and do the same for backgroundi mages but it doesnt work, anyone know what the link should be?

In your css it should be ../assets/img/myimage.jpg/ where ../ means "go up from the css folder and find the assets folder". Whereas in your case the css file was searchinf the assets directory INSIDE the css folder) Hope that's clear ;)

它应该是

../assets/img/all/myimage.jpg

You have to go up a folder level because you your css file is not within the root directory. You must add a ../ before the file path to navigate back up to the root directory like so.

../assets/img/myimage.jpg

If your css file was placed within the root directory you would not need to do this.

You will need to first back out of your css folder, then go into your img folder

to backout, use this logic "../"

so on your html page you would link to the image this way:

<img src='img/myimage.jpg'>

but in your css file you need to do it this way:

.class{
  background: url('../img/myimage.jpg');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM