2017-12-01 8 views
1

divの外にあるウェブサイトの背景を色にするにはどうすればよいですか? ここに私のコードのサンプル:親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

親コンテナまたは本体に背景色を設定しますか? – kmdm

+1

苦労して何をしたいのか分かりません..... –

+0

@kmdmは正しいです。本体をある背景色、すなわち 'body {background-color:#ccc;} 'に設定することができます。別の方法として、ページ全体を特定の背景色のdivにラップすることもできます。つまり、div.page-wrapper {width:100%;背景色:#ccc;} ' –

答えて

1

あなたはdiv1div2 & div3を取り巻くdivある親div、の背景色を変更する必要があります。

ここにある例LINK

+0

また、チュートリアルを見ることでたくさんのことを学ぶことができます。私はhttps://www.w3schools.com/css/default.aspをお勧めします:) – Srax

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>

0

ジャストスタイル=置く "背景色:赤;" bodyタグに入れたり、divを親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 ; 
 
}
<body style="background-color: red">   
 
    <div class="div1"></div> 
 
    <div class="div2"></div> 
 
    <div class="div3"></div> 
 
</body>

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>

関連する問題