亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

css - 關于margin折疊的一個問題。

瀏覽:106日期:2023-07-12 17:12:18

問題描述

我在閱讀CSS2.2,但是我真的無法理解這句話的意思,以及它所適合的場景:

If the top and bottom margins of an element with clearance p. 157 are adjoining, its margins collapse with the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block.

StackOverflow上有個家伙也提了一樣的問題,回答者的答案我也不理解。。。

借用采納者的知乎鏈接,這句的意思是:

If the top and bottom margins of an element with clearance are adjoining, its margins collapse with the adjoining margins of following siblings but that resulting margin does not collapse with the bottom margin of the parent block.(有間隙不折疊)

哪,什么才是有間隙呢?這里的間隙clearance在css2.2中有定義。來個例子,先有個直觀的理解吧:

<html><head> <style>* {padding: 0; margin: 0;}#b1 { width: 300px; height: 100px; margin-bottom: 4em; background-color: #0d8ba1;}#F { float: left; width: 100px; height: 70px; background-color: yellow;}#b2 { /*clear: both;*/ width: 300px; height: 100px; background-color: red; margin-top: 2em;} </style></head><body><p id='b1'></p><p id='F'></p><p id='b2'></p></body></html>

運行時,對比#b2有clear:both與沒clear:both時,b1與b2margin的折疊情況。

設置clear:both之后,#b2為了避開浮動的F,往下移動,出現了clearance也就是空隙,b1與b2不再折疊!

另外,stack overflow那個家伙的答案我沒再細究。pass。

問題解答

回答1:

可以看這里:https://www.zhihu.com/question/24563593

回答2:

這個說明也挺清晰的:http://www.raccoon-tech.com/css-margin-collapse

回答3:

只要理解 clearance 產生的條件是當 clear 的元素在沒有被 clear 的時候(正常時),它的 boarder top 要比 float 元素的 boarder bottom 要高。如果 clear 的元素本來就在 float 元素下面,就不會產生 clearance。

If this hypothetical position of the element’s top border edge is not past the relevant floats, then clearance is introduced, and margins collapse according to the rules in 8.3.1.

所以這個規則大白話就是:對于一個帶 clearance 的元素,當它 margin top 和 margin bottom 相鄰時(比如 height 為 0 、沒有 padding 和 border),這個兩個 margin 會跟接下來相鄰元素的 margin 一起計算 collapsing,但不會跟父元素的 margin bottom 計算(這情況下就是只算這兩個 margin)。

這里還要注意 clearance 計算是以 boarder edge 做參考,所以對于 margin top 和 margin bottom collapse 的元素,最后要注意還會吞掉與 margin top 相當的高度。

Then the amount of clearance is set to the greater of:

The amount necessary to place the border edge of the block even with the bottom outer edge of the lowest float that is to be cleared.

The amount necessary to place the top border edge of the block at its hypothetical position.

標簽: CSS
相關文章:
主站蜘蛛池模板: 中文字幕片| 天天干天天色综合网 | 国产成人久久777777 | 亚洲成人午夜影院 | 三级黄.色 | 国产精品一库二库三库 | 成人欧美1314www色视频 | 一及黄色 | 亚洲综合激情另类图片专区 | 欧美激情综合亚洲一二区 | 国产aaa三级 | 久久久国产高清 | 国产视频福利在线 | 国产激情在线观看 | 黄色片在线视频 | 国产成人短视频在线观看免费 | 高清一区二区亚洲欧美日韩 | 国产美女一级特黄毛片 | 亚洲线精品久久一区二区三区 | 国产另类图片 | 成人一a毛片免费视频 | 视频在线观看一区二区 | 中文字幕精品视频 | 亚洲日日 | 国产视频国产 | 欧美日韩无| 免费人成网址在线观看国内 | 玖玖精品在线视频 | 国产免费又色又爽又黄的网站 | 在线黄色小视频 | 黄色美国大片 | 2017天天鲁夜夜夜夜夜夜夜 | 国产精品亚洲综合久久小说 | 一二三区乱码一区二区三区码 | 成片免费观看视频在线网 | 黄色网页在线 | 黄色一级在线观看 | 国内三级视频 | 欧美日韩高清一本大道免费 | 黄色片子网站 | 中文字幕有码热在线视频 |