亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

clear:both 放置的位置

clear:both 放置的位置

躍然一笑 2018-11-07 13:13:42
css.container{    margin: 30px auto;    width:600px;    height: 300px;  }.p{    border:solid 3px #a33;  }.c{    width: 100px;    height: 100px;    background-color: #060;    margin: 10px;    float: left;  } <div class="container">      <div class="p">            <div style="clear:both">//為什么不能寫元素之前?           <div class="c"></div>            <div class="c"></div>            <div class="c"></div>                                                                                                                        <div style="clear:both">        </div>      </div>帶有clear屬性的元素為什么不能寫浮動元素之前?
查看完整描述

1 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

在 css 文檔里面規定 clear:both 的意思是:

要求框的頂邊框邊低于在源文檔中之前生成的任何浮動框的底外邊距邊。
Requires that the top border edge of the box be below the bottom outer edge of any right-floating and left-floating boxes that resulted from elements earlier in the source document.

所以有 clear:both 屬性的元素放在浮動元素之后才能起到閉合浮動的作用。
我一般清除浮動是通過浮動元素的父元素的偽元素實現的。在你這個例子中就是

.p:after{    clear:both;    display:block;    content:"";
}

after 偽元素是父元素的最后一個子元素,所以能清除這個塊里面的浮動。


查看完整回答
反對 回復 2018-12-10
  • 1 回答
  • 0 關注
  • 997 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號