浮動小数点の右または左のdivが、相対位置を持つdivの上にないか、最後のものが後に宣言されたときに背景色で定義される理由がわかりません。ここでdiv浮動体に対する相対位置を持つdiv
はhtmlです:
<html>
<body>
<div class="container">
Main container <br/><br/>
<div class="header">This is the header</div>
<div class="text-right">Right text</div>
<div class="footer">This is the footer</div>
</div>
</body>
そして、ここでは、CSSです:
.header {
background-color:blue;
border: solid;
color: white;
border-color:black;
height: 100px;
}
.text-right{
float: right;
border: solid;
background-color: green;
}
.container{
padding: 10px;
border: solid;
}
.footer{
padding-top: 50px;
border: solid;
background-color: yellow;
position: relative;
}
私は.clear使用できることを知っている:この問題を修正するために、両方のルールをが、私の主なポイントは:バックグラウンドカラーや位置またはその両方を.footerルールで設定すると、float divはフッターの下にあるのはなぜですか?
ありがとうございました!
同じ問題を示す最小限のJSFiddleの例があります:http://jsfiddle.net/5Kefa/5/ – KajMagnus