为什么body元素不使用overflow-y:auto但它的行为方式仍然相同?
我相信它默认是可见的,但它实际上是如何工作的?
解决方法
body(和html)标记是特殊情况,位于DOM层次结构的根目录下,浏览器必须将它们呈现为设置为auto.
这在CSS 2.1中的overflow
documentation on W3中有所概述:
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’.