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

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

css - 關(guān)于margin折疊的一個(gè)問(wèn)題。

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

問(wèn)題描述

我在閱讀CSS2.2,但是我真的無(wú)法理解這句話(huà)的意思,以及它所適合的場(chǎng)景:

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上有個(gè)家伙也提了一樣的問(wèn)題,回答者的答案我也不理解。。。

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

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中有定義。來(lái)個(gè)例子,先有個(gè)直觀的理解吧:

<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>

運(yùn)行時(shí),對(duì)比#b2有clear:both與沒(méi)clear:both時(shí),b1與b2margin的折疊情況。

設(shè)置clear:both之后,#b2為了避開(kāi)浮動(dòng)的F,往下移動(dòng),出現(xiàn)了clearance也就是空隙,b1與b2不再折疊!

另外,stack overflow那個(gè)家伙的答案我沒(méi)再細(xì)究。pass。

問(wèn)題解答

回答1:

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

回答2:

這個(gè)說(shuō)明也挺清晰的:http://www.raccoon-tech.com/css-margin-collapse

回答3:

只要理解 clearance 產(chǎn)生的條件是當(dāng) clear 的元素在沒(méi)有被 clear 的時(shí)候(正常時(shí)),它的 boarder top 要比 float 元素的 boarder bottom 要高。如果 clear 的元素本來(lái)就在 float 元素下面,就不會(huì)產(chǎn)生 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.

所以這個(gè)規(guī)則大白話(huà)就是:對(duì)于一個(gè)帶 clearance 的元素,當(dāng)它 margin top 和 margin bottom 相鄰時(shí)(比如 height 為 0 、沒(méi)有 padding 和 border),這個(gè)兩個(gè) margin 會(huì)跟接下來(lái)相鄰元素的 margin 一起計(jì)算 collapsing,但不會(huì)跟父元素的 margin bottom 計(jì)算(這情況下就是只算這兩個(gè) margin)。

這里還要注意 clearance 計(jì)算是以 boarder edge 做參考,所以對(duì)于 margin top 和 margin bottom collapse 的元素,最后要注意還會(huì)吞掉與 margin top 相當(dāng)?shù)母叨取?/p>

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.

標(biāo)簽: CSS
相關(guān)文章:
主站蜘蛛池模板: 欧美一区二区三区不卡免费观看 | 欧美 日韩 国产 成人 在线观看 | 国产v在线播放 | 色天使色婷婷丁香久久综合 | 日韩欧美一区二区三区视频 | julia一区福利视频在线观看 | 国产福利在线观看一区二区 | 哪里可以看黄色播放免费 | 欧美日本韩国一区二区 | 91久久国产露脸精品免费 | 亚洲香蕉毛片久久网站老妇人 | 99久久精品国产一区二区 | 亚洲精品成人一区 | 在线视频观看亚洲 | 尤物视频在线观看网站 | 亚洲欧美日韩国产精品 | 亚洲精品丝袜在线一区波多野结衣 | 国产美女久久久久 | 男女刺激大片免费观看网站 | 日韩欧美特一级大黄作a毛片免费 | 国内精品视频在线观看 | 久久9966e这里只有精品 | 欧美激情视频网址 | 成人短视频在线在线观看 | 男女配种超爽免费视频 | 日韩久久中文字幕 | 日本亚洲国产 | 毛片免费观看久久欧美 | 91青娱乐在线 | 欧美成a人片在线观看久 | 久久久久久91精品色婷婷 | 亚洲精品香蕉一区二区 | 草草草视频在线观看 | 日本在线精品视频 | www.国产成人| 欧美日韩成人高清在线播放 | 亚洲欧美日韩中文高清ww | 青青草国产免费一区二区 | 国产麻豆入在线观看 | 国产精品一区在线观看你懂的 | 91大神大战丝袜美女在线观看 |