css float 屬性解析

來源:互聯網
上載者:User

標籤:c   class   blog   a   http   width   

     float 屬性的定義:使元素在哪個方向浮動

             預設值為:none

            注意:浮動元素會產生一個塊級框,而不論它本身是何種元素

HTML代碼:

<body>     <div class="main"> <div class="d" id="d1">框1</div> <div class="d" id="d2">框2</div>  <div class="d" id="d3">框3</div> <div class="d" id="d4">框4</div>       </div></body>

 1,當兄弟元素全為浮動元素時其父類元素在沒有自訂寬高時其高度將為零

css樣式:

.main {      border: 1px solid ;   }
.d { border: 1px solid red; width: 50px; height: 50px; float: left; }

 

顯示效果:

2,浮動元素會在一行之內空間不夠多餘的浮動元素會跳至下一行

css樣式:

 .main {      border: 1px solid ;      width:130px;   } .d {      border: 1px solid red;      width: 50px;      height: 50px;      float: left;   }

 

顯示效果:

3,浮動元素會脫離文字資料流,其參照父類元素

ccs樣式:

  #d1{     float:left;   }

 顯示:

 

 

 

 

 

     

            

                     

                     

             

聯繫我們

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