萬能清除浮動樣式

來源:互聯網
上載者:User
這個是一個很流行的清除浮動的方法,在很多大項目上已經被完全採用。

這個方法來源於positioniseverything,通過after偽類:after和IEhack來實現,完全相容當前主流瀏覽器。

.clearfix:after  {    content: ".";    clear: both;    height: 0;    visibility: hidden;    display: block;  } /* 這是對Firefox進行的處理,因為Firefox支援產生元素,而IE所有版本都不支援產生元素 */ .clearfix{display: inline-block;} /* 這是對 Mac 上的IE瀏覽器進行的處理 */ * html .clearfix{ height: 1%; } /* 這是對 Win上 的 IE6 瀏覽器進行的處理 */ * + html .clearfix{ height: 1%; } /* 這是對 Win 上的 IE7 瀏覽器進行的處理 */ .clearfix{display: block;} /* 這是對display: inline-block;進行的修改,重設為區塊元素*/

下面給一個admin10000.com 用的清理浮動的代碼

.clearfix:after {    content: "020";    display: block;    height: 0;    clear: both;}.clearfix {    zoom: 1;}

這個是最佳化版的清除浮動的樣式,很值得推薦。

相關文檔:CSS清除浮動常用方法小結

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.