根据 Mozilla 开发者网络的 article关于 CSS position
属性(property)、环境position
如absolute
有以下行为:
absolute
block 引用>Do not leave space for the element. Instead, position it at a specified position relative to its closest positioned ancestor if any, or otherwise relative to the initial containing block. Absolutely positioned boxes can have margins, and they do not collapse with any other margins.
然而在官方CSS specification as of 2015我找不到它在哪里声明了包含框或最近祖先需要定位的约束(即必须具有
relative
、absolute
、fixed
或sticky
的计算定位属性)。它是如何推论或暗示的?
最佳答案
它在规范中(您查看的是错误的文档):
The containing block for a positioned box is established by the nearest positioned ancestor (or, if none exists, the initial containing block).
这也是相关的:
9.3.2 Box offsets:
top
,right
,bottom
,left
An element is said to be positioned if its
position
property has a value other thanstatic
.
关于css - CSS规范中找不到绝对定位规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41306265/