我在ASP.NET中有一个页面,如下所示。如何在添加内容时保持CSS布局(ASP.NET)
的jsfiddle http://jsfiddle.net/nyrUp/
HTML
<div class="mainContainer">
<div>
<div class="topLeft">
<% =DateTime.Now.Ticks.ToString()%>
</div>
<div class="topRight">
foo
</div>
</div>
<div>
<div class="bottomLeft">
foo
</div>
<div class="bottomRight">
foo
</div>
</div>
<div class="underneath">
foo
</div>
</div>
CSS
.mainContainer {
}
.topLeft {
width: 50%;
float: left;
background-color: red;
}
.topRight {
width: 50%;
float: left;
background-color: orange;
}
.bottomLeft {
width: 50%;
float: left;
background-color: yellow;
}
.bottomRight {
width: 50%;
float: left;
background-color: green;
}
.underneath {
width: 100%;
background-color: blue;
}
这工作得很好,直到你将内容添加到任何DIV,此时布局被打破
的jsfiddle显示破碎的布局:http://jsfiddle.net/4gbP8/
如何在添加内容时保持此布局?
即
你在下面有一些很好的答案。我会添加一些很好的资源来阅读关于“clearfix”的讨论:[PositionIsEverything.com](http://www.positioniseverything.net/easyclearing.html),[Clearfix Micro](http://nicolasgallagher.com/ micro-clearfix-hack /) – jmbertucci 2013-05-09 13:54:23