css清除浮動主要方法

來源:互聯網
上載者:User

標籤:clear   style   瀏覽器   hidden   span   oat   使用   問題   頁面   

1、浮動元素尾部添加空div標籤,設定css為clear:both;

缺點:如果頁面浮動布局多,則需要添加較多div;

 

2、父級元素定義偽類:after和zoom:1;

.father:after{display:block;clear:both;content:"";visibility:hidden;height:0}.father{zoom:1}

推薦使用,定義公用類,減少css代碼;

 

3、父級元素使用overflow:hidden;

原理:父級元素還必須設定boom:1或者width,且不能定義高度,因為使用overflow:hidden時,瀏覽器會自動檢測浮動地區的高度;

缺點:不能配合position使用;

 

4、父級元素添加display:table;

缺點:盒模型屬性已經改變,由此造成的一系列問題,得不償失,不推薦使用;

 

而外不推薦使用的方法有:父級元素定義float;使用overflow:auto;

 

css清除浮動主要方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.