我看到這個,而不同的clearfix這裏方法:http://www.marcwatts.com.au/blog/best-clearfix-ever/「有史以來最好的清除補丁?」
它提議增列它會自動clearfix,並不需要你到「clearfix」或類似的類添加到要清除的元素下面的CSS代碼。
/* our Global CSS file */
article:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
aside:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
div:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
footer:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
form:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
header:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
nav:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
section:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
ul:after { clear:both; content:"."; display:block; height:0; visibility:hidden; }
/* our ie CSS file */
article { zoom:1; }
aside { zoom:1; }
div { zoom:1; }
footer { zoom:1; }
form { zoom:1; }
header { zoom:1; }
nav { zoom:1; }
section { zoom:1; }
ul { zoom:1; }
這種方法有什麼缺點嗎?這可能會最終澄清你的元素,你可能不一定希望clearfix'ed?還是這樣的規則可以解釋任何情況?
不相關,但是您是否知道可以爲一組規則使用多個CSS選擇器?不需要複製CSS。例如:'nav,div,header,section,ul li a,p strong {zoom:1}' – 2011-06-07 23:40:49
嗯,你真的應該定義多個css選擇器:'article:after,aside:after,div:after,... {明確:兩者; ...}' – 2011-06-07 23:41:14
我知道,我只是將它粘貼在該網站上。我注意到了。 ;) – 2011-06-08 02:59:51