CSS中清除浮動的最好用的方法之一的詳細介紹(附代碼)

來源:互聯網
上載者:User

這篇文章給大家分享的內容是關於CSS中清除浮動的最好用的方法之一的詳細介紹(附代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

我們寫網頁常常為浮動帶來的影響而煩惱,因為子項目浮動導致父元素沒有高,從而網頁錯亂,達不到自己想要的結果。
清除浮動,我只推薦這種方法!
下面這個方法是我從學前端用到現在的,也沒想換過,因為太好用了:

.clearfix:after{    content: "";    height:0;    line-height: 0;    display:block;    visibility: hidden;    clear:both;}

具體用法:

<ul class="clearfix">    <li style="float:left;"></li>    <li style="float:left;"></li>    <li style="float:left;"></li>    <li style="float:left;"></li></ul>

子項目浮動了,給父元素加上這個類即可,百試不爽!

因為這個樣式經常用,建議加到公用樣式裡面去哦!

相關文章

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.