【发布时间】:2015-12-28 01:31:21
【问题描述】:
我不明白为什么当最后一个被声明时,具有左右浮动的 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: both 规则来纠正这个问题,但我的主要观点是:为什么当我在 .footer 规则中设置背景颜色或位置或两者时,浮动 div 在页脚?
非常感谢!
【问题讨论】:
-
这是一个简约的 JSFiddle 示例,显示了同样的问题:jsfiddle.net/5Kefa/5
标签: css html position css-float