javascript - 關(guān)于使用overflow: hidden來(lái)清除浮動(dòng)的疑問(wèn)
問(wèn)題描述
正常情況下,給浮動(dòng)的父元素設(shè)置overflow:hidden;就可以清楚浮動(dòng),但是我發(fā)現(xiàn)被浮動(dòng)元素的父元素是body時(shí),給body設(shè)置overflow:hidden,是無(wú)法清除浮動(dòng)的,有人說(shuō)是body不屬于普通流,所以無(wú)效,有誰(shuí)能解釋下嗎?
感謝:CRIMX借用王大陸的一句話:
你這種人不是大神,就是走在成為大神的路上。
問(wèn)題解答
回答1:這是因?yàn)椴](méi)有產(chǎn)生新的 BFC
產(chǎn)生新 BFC 的一個(gè)條件:
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).
為什么對(duì) <body> 設(shè)置 overflow 會(huì)擴(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. javascript - sublime快鍵鍵問(wèn)題2. javascript - immutable配合react提升性能?3. macos - 如何徹底刪除mac自帶的apache和php4. DADB.class.php文件的代碼怎么寫5. mysql - 在log日志中已知用戶的某一步操作,如何獲取其上一步操作?6. shell - mysql更新錯(cuò)誤7. 網(wǎng)頁(yè)爬蟲 - 如何使用使用java抓取信息并制作一個(gè)排名系統(tǒng)?8. 如何設(shè)置一個(gè)無(wú)限循環(huán)并打破它。(Java線程)9. python小白 自學(xué)看書遇到看不懂的地方10. php對(duì)mysql提取數(shù)據(jù)那種速度更快

網(wǎng)公網(wǎng)安備