Home > Web Front-end > Front-end Q&A > What should I do if css cannot display the background?

What should I do if css cannot display the background?

藏色散人
Release: 2023-02-01 09:59:55
Original
5218 people have browsed it

Solution to css unable to display the background: 1. Check whether css has been called and re-call the correct css path; 2. Check the css image address and modify it correctly; 3. Fixed the height of the div; 4. Check Whether the div is nested and modified; 5. Just standardize the div code.

What should I do if css cannot display the background?

The operating environment of this tutorial: Windows 10 system, CSS3 version, DELL G3 computer

What should I do if the css cannot display the background?

Solutions to the div background image or color not being displayed

The reasons why the background image is not displayed mainly include the following aspects:

1. css is not called

2. The css image address is incorrect

3. The height of the div is not fixed, it is auto, has no value set, or the height is not high enough

4. div Nested

5. The div code is not standardized

Solution:

-The DIV height is automatic and the background color cannot be displayed. In the code Change the original code height:auto; to height:100%; overflow:hidden;!important; it is also compatible with IE6, 7, 8 and Google Firefox.

- Assume that the background color style is set for an object, and the internal box of the object uses the float attribute style. At this time, the object floats, causing the object to not be opened, so the css background color cannot be used. It shows that there are three solutions. One is to set clear to clear float, set css height, and set css overflow style.

- The height limit causes the background color to not be displayed completely. If you have an object that has not calculated the height (or accidentally set a very small height attribute style), because you are not sure how much content there is, when the content exceeds your Set a height limit. At this time, part of the background may not be displayed. Set the height high enough, or cancel the deletion of the height style.

Case:

<div style="width:960px;background-color:#000000">
    <div  style="width:300px; height:200px; float:left">左侧</div>
    <div  style="width:300px; height:200px; float:left">中部</div>
    <div  style="width:360px; height:200px; float:left">右侧</div>
</div>
Copy after login

Because the height of the outer div is not set, after setting the above code, you will see three transparent boxes.

The correct code is as follows :

<div style="width:960px; height:200px;background-color:#000000">
    <div  style="width:300px; height:200px; float:left">左侧</div>
    <div  style="width:300px; height:200px; float:left">中部</div>
    <div  style="width:360px; height:200px; float:left">右侧</div>
</div>
Copy after login

Recommended study: "css video tutorial"

The above is the detailed content of What should I do if css cannot display the background?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template