如何更改父div的背景颜色?

时间:2017-12-01 15:26:21

标签: html css

如何在div之外获取我的网站背景颜色? 这是我的代码示例:

.div1 {
    border: 1px solid black;
    height:400px;
    width:1000px;
    margin-left: auto ;
    margin-right: none ;
    image-repeat: no-repeat;
    img-position: top right;
    text-align: left
}


.div2 {
    border: 1px solid black;
    height:750px;
    width:1000px;
    margin-left: none ;
    margin-right: auto ;
    background-repeat: no-repeat;
    background-position: left;
    text-align: center
}


.div3 {
    border: 1px solid black;
    height:470px;
    width:1000px;
    margin-left: auto ;
    margin-right: none ;
}

任何帮助将不胜感激。我已经尝试了我能想到的一切,但我什么也没做到。

3 个答案:

答案 0 :(得分:1)

您必须更改父div的背景颜色,div围绕div1div2& div3

以下是LINK

的示例

答案 1 :(得分:0)

这是一个简单的代码示例:



<!DOCTYPE html>

<html>

    <head>
        <title>Test Table</title>

        <style type="text/css"> 
            body {
                background-color: orange;
            }

            .div1 {
                border: 1px solid black;
                height:400px;
                width:1000px;
                margin-left: auto ;
                margin-right: none ;
                text-align: left;
                background-color: blue;
            }

            .div2 {
                border: 1px solid black;
                height:750px;
                width:1000px;
                margin-left: none ;
                margin-right: auto ;
                background-repeat: no-repeat;
                background-position: left;
                text-align: center;
                background-color: green;
            }

            .div3 {
                border: 1px solid black;
                height:470px;
                width:1000px;
                margin-left: auto ;
                margin-right: none ;
                background-color: red;
            }
        </style>
    </head>

    <body>
        <div class="div1">DIV 1</div>
        <div class="div2">DIV 2</div>  
        <div class="div3">DIV 3</div>  
    </body>

</html>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

body {
    background-color: lightblue;
}

.div1 {
    border: 1px solid black;
    height:50px;
    width:50px;
    margin-left: auto ;
    margin-right: none ;
    image-repeat: no-repeat;
    img-position: top right;
    text-align: left
}


.div2 {
    border: 1px solid black;
    height:50px;
    width:50px;
    margin-left: none ;
    margin-right: auto ;
    background-repeat: no-repeat;
    background-position: left;
    text-align: center
}


.div3 {
    border: 1px solid black;
    height:50px;
    width:50px;
    margin-left: auto ;
    margin-right: none ;
}
<div class='div1'>div 1</div>
<div class='div2'>div 2</div>
<div class='div3'>div 3</div>