【发布时间】:2010-12-14 20:56:28
【问题描述】:
所以我很难理解浮动在哪些情况下可能会导致边距塌陷,以及这如何影响浮动的位置。我添加了一个页面,该页面似乎在同一页面中显示了两种不同的行为。
红色浮动似乎定位在通过它折叠的边距之前,而下方的蓝色浮动似乎有边折叠通过它们,然后定位在这些边距折叠之后。
任何帮助将不胜感激。
干杯, 本
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Inheritance Tests</title>
<style>
* {
margin: 0px ;
padding: 0px ;
font-family: courier ;
font-size: small ;
}
.test4 {width: 200px; height: 100px; border-style: solid; border-width: 1px;}
.test5 {border: 1px solid red; width: 200px; height: 50px; float: left; }
.floatedRect {
width: 50px ;
height: 50px ;
float: left ;
background-color: #9cf ;
}
.text {
margin: 10px ;
}
</style>
</head>
<body>
<div class="test4">
Normal Flow
</div>
<div class="test5">
Floated
</div>
<div style="margin-top: 100px">
Has a top margin
</div>
<div style="clear: both">
<div class="floatedRect"></div>
<div class="text">some text</div>
<div class="floatedRect"></div>
<div class="text">some text</div>
<div class="floatedRect"></div>
<div class="text">some text</div>
</div>
</body>
</html>
【问题讨论】:
-
有点难以理解你在问什么。您是否正在尝试解决某个特定问题?您能描述一下您希望在此示例中看到的内容吗?
标签: html css css-float margin collapse