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

What should I do if css cannot display the background?

藏色散人
藏色散人Original
2023-02-01 09:59:555123browse

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>

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>

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!

Statement:
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