When I used to write web pages in HTML, I linked external css style sheets to the web page. Others like: background-color, padding, margin, etc. all worked normally, but background-image did not work, and Sometimes background-image:url(""absolute path""); can be displayed in a fit of anger, but we strongly discourage this way of writing absolute paths, so what is the reason for this phenomenon?
**
Note: The background-image:url written in the css style sheet (the path of the image is relative to the path of this css file, not the relative adding css style that we usually think of The path of the web page);
**
For example: In the current directory, there are index.html and css folders (which contain: css.css) and images folders (which contain top .jpg)
Wrong thinking and writing: background-image:url("images/top.jpg"); ———————————–>>Error I think the path of the image should be for the index.html web page.
Correct thinking and writing method: background-image:url(“../images/top.jpg”);————————————>Path of the image What should be written is the path relative to the css.css file
where ../ represents the upper-level directory, do not write ./ which represents the current directory.
This problem has troubled me for a long time. I will summarize it today and remind myself! ! I hope those who haven’t figured it out yet will understand!
The above is the detailed content of How to solve the problem of background image not loading. For more information, please follow other related articles on the PHP Chinese website!