javascript - 关于使用overflow: hidden来清除浮动的疑问
世界只因有你
世界只因有你 2017-05-16 13:36:43
[HTML讨论组]

正常情况下,给浮动的父元素设置overflow:hidden;就可以清楚浮动,但是我发现被浮动元素的父元素是body时,给body设置overflow:hidden,是无法清除浮动的,有人说是body不属于普通流,所以无效,有谁能解释下吗?

感谢:CRIMX
借用王大陆的一句话:

你这种人不是大神,就是走在成为大神的路上。

世界只因有你
世界只因有你

全部回复(1)
为情所困

这是因为并没有产生新的 BFC

产生新 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> 设置 overflow 会扩散到 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'.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号