浮动本来是用在文字环绕图片,
现在却被用来排版,替代很久以前的表格式排版。
清除浮动两种方式,一种是在包裹浮动元素的大框加:after,
<style type="text/css"> .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } .clearfix {display: inline-block;} /* for IE/Mac */ </style><!-- main stylesheet ends, CC with new stylesheet below... --> <!--[if IE]> <style type="text/css"> .clearfix { zoom: 1; /* triggers hasLayout */ <span style="color: #aa0000;">display: block; /* resets display for IE/Win */</span> } /* Only IE can see inside the conditional comment and read this CSS rule. Don't ever use a normal HTML comment inside the CC or it will close prematurely. */ </style> <![endif]-->
另一种是添加新元素,
html body div.clear, html body span.clear { background: none; border: 0; clear: both; display: block; float: none; font-size: 0; margin: 0; padding: 0; overflow: hidden; visibility: hidden; width: 0; height: 0; }
还有第三种方案,压根不用float,用inline-block来设置li元素或a元素。
这点在m.tmall.com里面运用尤其明显。