<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml xml:lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/vnd.wap.wml; charset=utf-8"/>
<meta http-equiv="Cache-Control" content="no-cache"/></head>
<card title="别忘记清除浮动 - Gracecode.com">
<p>很早的时候，<a href="http://www.planabc.net/" title="http://www.planabc.net/">圆心</a> 就告诫我，“要随时清楚浮动元素”。当时由于忙（也许这算不上是借口），我把他的话当作了耳边风。</p>

<p>今天偏偏在工作最为忙乱的时候，运营那边在添加数据时，发现页面乱了。幸好又是伟大的 圆心 同志帮我找到了这个老问题，并解决（大哥在上，请接受小弟一拜）。</p>

<p>总结下清除浮动的一般解决方案，更多的总结可以<a href="http://www.wondger.com/blog/article.asp?id=32" title="http://www.wondger.com/blog/article.asp?id=32">看这里</a>。</p>

<h2>用空标签清除</h2><pre>.clr {clear: both;}

&lt;div id=&quot;layout&quot;&gt;
    &lt;div id=&quot;left&quot;&gt;Left&lt;/div&gt;
    &lt;div id=&quot;right&quot;&gt;Right&lt;/div&gt;
    &lt;p class=&quot;clr&quot;&gt;&lt;/p&gt;
&lt;/div&gt;</pre><h2>使用 overflow 属性</h2><pre>#layout {overflow:auto; zoom:1;}

&lt;div id=&quot;layout&quot;&gt;
    &lt;div id=&quot;left&quot;&gt;Left&lt;/div&gt;
    &lt;div id=&quot;right&quot;&gt;Right&lt;/div&gt;
&lt;/div&gt;</pre><h2>使用 :after （非 IE 浏览器）</h2><pre>#layout:after{
    display: block;
    clear: both; content: &quot;&quot;;
    visibility:hidden; height: 0;
}

&lt;div id=&quot;layout&quot;&gt;
    &lt;div id=&quot;left&quot;&gt;Left&lt;/div&gt;
    &lt;div id=&quot;right&quot;&gt;Right&lt;/div&gt;
&lt;/div&gt;</pre><p>注：使用 :after 需要注意几点，设置高度为零（height: 0;）；content 是必须的，但其值可以为空。</p>


<p>
<a href="http://www.gracecode.com/wap/">Gracecode.com</a> |
<a href="http://www.gracecode.com/wap/d/1209 ">Permalink</a>(<a href="http://www.gracecode.com/Archive/Display/1209 ">xHTML</a>) |
<a href="http://www.gracecode.com/Trackback/Recieve/1209/ewp31v">Trackback</a> |
<a href="http://rss.gracecode.com">Rss</a>
</p>
</card>
</wml>