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. boot2docker無(wú)法啟動(dòng)2. docker-compose中volumes的問(wèn)題3. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””4. nignx - docker內(nèi)nginx 80端口被占用5. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.6. javascript - mock.js可以存儲(chǔ)數(shù)據(jù)嗎7. java - SSH框架中寫(xiě)分頁(yè)時(shí)service層中不能注入分頁(yè)類8. golang - 用IDE看docker源碼時(shí)的小問(wèn)題9. docker api 開(kāi)發(fā)的端口怎么獲取?10. dockerfile - 為什么docker容器啟動(dòng)不了?

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