css清除浮動的8種方法

來源:互聯網
上載者:User

標籤:使用   pre   網易   div   推薦   代碼   idt   oom   來源   

參考來源:http://www.jb51.net/css/173023.html

常用方法如下:

<style type="text/css"> .div1{background:#000080;border:1px solid red;} .div2{background:#800080;border:1px solid red;height:100px;margin-top:10px} .left{float:left;width:20%;height:200px;background:#DDD} .right{float:right;width:30%;height:80px;background:#DDD} /*清除浮動代碼*/ .clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0} .clearfloat{zoom:1} </style> <div class="div1 clearfloat"> <div class="left">Left</div> <div class="right">Right</div> </div> <div class="div2"> div2 </div> 

原理:IE8以上和非IE瀏覽器才支援:after,原理和方法2有點類似,zoom(IE轉有屬性)可解決ie6,ie7浮動問題 

優點:瀏覽器支援好、不容易出現怪問題(目前:大型網站都有使用,如:騰迅,網易,新浪等等) 

缺點:代碼多、不少初學者不理解原理,要兩句代碼結合使用才能讓主流瀏覽器都支援。 

建議:推薦使用,建議定義公用類,以減少CSS代碼。 

css清除浮動的8種方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.