javascript - 关于使用overflow: hidden来清除浮动的疑问
问题描述
正常情况下,给浮动的父元素设置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’.
相关文章:
1. 网页爬虫 - 关于Python的编码与解码问题2. css3 - 微信前端页面遇到的transition过渡动画的bug3. 前端 - WebStrom安装了angularjs插件,但是没有语法提示4. php - 微信开发验证服务器有效性5. java导入问题6. javascript - vue.js 在使用期间遇到ios9.3.2不兼容问题7. css - 文字排版问题,内容都是动态抓出来的,字数不一定。如何对齐啊8. javascript - Ajax返回json格式之后的数据解析后取出来的数据为undefined?9. 正则表达式 - Java:字符串替换带序号10. javascript - npm安装报错 系统w7 求大神解答

网公网安备