gpt4 book ai didi

html - "position: relative"到底是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-04 09:40:00 24 4
gpt4 key购买 nike

w3.org/TR/CSS2 says :

For other elements, if the element's position is 'relative' or 'static', the containing block is formed by the content edge of the nearest block container ancestor box.

这是什么意思?我将其解读为 position: relative 不会影响元素本身,但实际上会影响其父元素 - 包含 block

那么,要更改 包含 block 的 CSS,我是否必须将 position 应用于其子 block ?

是不是很奇怪?当您将 position: relative 应用于父级,并将 position: absolute 应用于其某些子级时,存在一种模式,以使绝对定位的子级与父级绑定(bind)。

最佳答案

...actually affects its parent - the containing block.

重点

... if the element's position is 'relative' or 'static', the containing block is formed by the content edge of the nearest block container ancestor box.

是为了说明它的parent不一定是它的包含 block 。

最值得注意的是,如果它是position:relative 并且它的父级是display:inline,那么它的父级不是它的包含 block ,但取而代之的是 DOM 树更上层的元素。

关于html - "position: relative"到底是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40013766/

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