Solution to the problem that the background image set in CSS cannot be displayed

Source: Internet
Author: User

When I wrote a webpage in HTML, <LINK rel = "stylesheet" type = "text/CSS" href = "CSS/css.css"/> link an external CSS style sheet to a webpage. Other images include background-color. padding, margin, and so on can work normally, but it means that the background-image does not work, and sometimes the background-image: URL ("" absolute path "") is in the air; it can be displayed, but we do not advocate the writing of this absolute path. What is the reason for this phenomenon?

Note ::Background-image: URL written in the CSS style sheet (the path of the image is relative to the path of the current CSS file, rather than the path of the webpage that we usually consider to be relatively added to the CSS style);

For example, the current directory contains the index.html and CSS folders (including: css.css) and the imagesfolder (crouton containing top.jpg)

Incorrect description and Syntax: Background-image: URL ("images/top.jpg"); -------------------------------------> the incorrect description of the image should be based on the index.html webpage.

Correct thinking and writing:Background-image: URL ("../images/top.jpg ");-----------------------------------> The image must be written in the path of the relative css.css file.

Where../Indicates the upper-level directoryDo not write it as./. This indicates the current directory.

When I wrote a webpage in HTML, <LINK rel = "stylesheet" type = "text/CSS" href = "CSS/css.css"/> link an external CSS style sheet to a webpage. Other images include background-color. padding, margin, and so on can work normally, but it means that the background-image does not work, and sometimes the background-image: URL ("" absolute path "") is in the air; it can be displayed, but we do not advocate the writing of this absolute path. What is the reason for this phenomenon?

Note ::Background-image: URL written in the CSS style sheet (the path of the image is relative to the path of the current CSS file, rather than the path of the webpage that we usually consider to be relatively added to the CSS style);

For example, the current directory contains the index.html and CSS folders (including: css.css) and the imagesfolder (crouton containing top.jpg)

Incorrect description and Syntax: Background-image: URL ("images/top.jpg"); -------------------------------------> the incorrect description of the image should be based on the index.html webpage.

Correct thinking and writing:Background-image: URL ("../images/top.jpg ");-----------------------------------> The image must be written in the path of the relative css.css file.

Where../Indicates the upper-level directoryDo not write it as./. This indicates the current directory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.