javascript - 關(guān)于使用overflow: hidden來清除浮動的疑問
問題描述
正常情況下,給浮動的父元素設(shè)置overflow:hidden;就可以清楚浮動,但是我發(fā)現(xiàn)被浮動元素的父元素是body時,給body設(shè)置overflow:hidden,是無法清除浮動的,有人說是body不屬于普通流,所以無效,有誰能解釋下嗎?
感謝:CRIMX借用王大陸的一句話:
你這種人不是大神,就是走在成為大神的路上。
問題解答
回答1:這是因為并沒有產(chǎn)生新的 BFC
產(chǎn)生新 BFC 的一個條件:
Block-level, non-replaced elements in normal flow when ’overflow’ does not compute to ’visible’ (except if the ’overflow’ property’s value has been propagated to the viewport).
為什么對 <body> 設(shè)置 overflow 會擴(kuò)散到 viewport:
UAs must apply the ’overflow’ property set on the root element to the viewport. When the root element is an HTML 'HTML' element or an XHTML 'html' element, and that element has an HTML 'BODY' element or an XHTML 'body' element as a child, user agents must instead apply the ’overflow’ property from the first such child element to the viewport, if the value on the root element is ’visible’. The ’visible’ value when used for the viewport must be interpreted as ’auto’. The element from which the value is propagated must have a used value for ’overflow’ of ’visible’.
相關(guān)文章:
1. MySQL的聯(lián)合查詢[union]有什么實際的用處2. 怎么能做出標(biāo)簽切換頁的效果,(文字內(nèi)容隨動)3. mysql - sql 左連接結(jié)果union右連接結(jié)果,導(dǎo)致重復(fù)性計算怎么解決?4. 從git上下載的laravel項目不能用5. 數(shù)組排序,并把排序后的值存入到新數(shù)組中6. php多任務(wù)倒計時求助7. mysql 遠(yuǎn)程連接出錯10060,我已經(jīng)設(shè)置了任意主機(jī)了。。。8. mysql怎么表示兩個字段的差9. PHP訂單派單系統(tǒng)10. 默認(rèn)輸出類型為json,如何輸出html
