gpt4 book ai didi

css - 相同的 CSS 在应用于 body 或 div 时表现不同

转载 作者:技术小花猫 更新时间:2023-10-29 11:40:29 24 4
gpt4 key购买 nike

Using a DIV as container

<div class="container">
<div class="half-hidden"></div>
</div>

CSS

.container {
margin: 20px auto 0;
width: 200px;
height: 200px;

border: 1px solid red;
position: relative;
overflow: hidden;
}

.half-hidden {
position: absolute;
top: 10px;
bottom: 10px;
left: -50px;
width: 100px;

border: 1px solid teal;
}

Rendered page with a container

Using body as container

<div class="half-hidden"></div>

CSS

将上面的.container替换为body

Rendered page using body as container

为什么?

最佳答案

作为W3 Offical Doc说,@Andy G 也没有溢出。在这种情况下,UA 将对第一个 child 应用溢出:

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'.

关于css - 相同的 CSS 在应用于 body 或 div 时表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23898252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com