简体   繁体   中英

Local Background Image Not Loading

This one seems simple but wont work for some reason. I have a background-image (locally) in css like this:

#header { background-image: url('/../img/students.jpg'); }
/*also tried this */ #header { background-image: url('../img/students.jpg'); }

But it wont load. Here is the directory structure:

---css
-------styles.css
---img
-------students.jpg

Anything I am missing?

This should have worked.

#header { 
    background-image: url('../img/students.jpg'); 
}

Also, this should work as well

#header { 
    background-image: url('/img/students.jpg'); 
}

My guess is that you're having some caching issues. Your first attempt was wrong, /../img/students.jpg goes one level above the document root, which is not possible. Maybe this css with this error has been cached by your browser, try hitting CTRL + F5 several times (or completly clear the browser's cache) once you have fixed your css file with one of the solutions above.

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