簡體   English   中英

如何在HTML中保持父分區的背景色

[英]How to maintain the background color of parent division in HTML

我正在制作一個網頁(問題下方的代碼)。 因為我有一個主要部門,其寬度為90%,背景顏色為白色。 在該划分中,我又做了4個划分,其中該划分為4個相等的象限。 我希望所有這些部門都將白色作為背景,但是它們采用了body標簽的bgcolor屬性。 我如何使這些部門與其父部門的背景相同?

碼:

<body bgcolor="grey">
<div  style="width: 90%;  margin:0 auto; text-align:justify;  background-color: white;" >
    <div id="div1" align="center" style="width: 50%; height: 50%; float: left; background-color: white;">
        <h3> This Division </h3>
        <h4>With separate bg attr</h4>
        <table>
        <thead>
        <tr>
            <th>A</th>
            <th>B</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td> C </td>
            <td> 756 </td>
        </tr>
        <tr>
            <td>D</td>
            <td>749</td>            
        </tr>
        <tr>
            <td onclick="display('test');">E</td>
            <td>8</td>
        </tr>
        </tbody>
        </table>
    </div>
    <div id="div2" style="width: 50%; height: 50%; float: left;"> This is division 2</div>
    <div id="div3" style="width: 50%; height: 50%; float: left;">This is division 3 </div>
    <div id="div4" style="width: 50%; height: 50%; float: left;">This is division 4</div>

</div>

問題是您對孩子Div使用的是Float:left,對父div使用的是不浮動的,這就是為什么父div未填充該區域的原因

只需將float:left添加到父div,即可按需運行

<div  style="width: 90%;  margin:0 auto; text-align:justify;  background-color: white;float;left" >

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM