css - 包含没有 "top"、 "right"、 "bottom"或 "left"的绝对定位元素的 block

标签 css position css-position

我记得很久以前在某个地方读过,绝对定位一个元素而不给它任何 toprightbottomleft 属性将(与任何定位元素一样)将其从流中取出,但将其保留在同一个包含 block 中(静态定位时它应该在的那个包含 block )。

在下面的示例 ( jsFiddle ) 中,元素 #2 和 #3 是绝对定位的,但 #2 没有任何附加属性。

enter image description here

我一直在寻找解释该行为的文档,以便我可以继续使用它而不必担心可能的反斜杠,但在 Gooogle 或 SO 上并不幸运。有人能指出我正确的方向吗?

最佳答案

对于绝对定位的元素,偏移量(topleft 等)的默认值为auto

在这种情况下,即使内容已从文档流中取出,该元素仍保留在它应有的位置 position: static

对“静态位置”概念的引用包括:

http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-width

http://www.w3.org/TR/CSS2/visudet.html#abs-non-replaced-height

http://www.w3.org/TR/CSS2/visuren.html#position-props

引用:

10.3.7 Absolutely positioned, non-replaced elements

For the purposes of this section and the next, the term "static position" (of an element) refers, roughly, to the position an element would have had in the normal flow. More precisely:

The static-position containing block is the containing block of a hypothetical box that would have been the first box of the element if its specified 'position' value had been 'static' and its specified 'float' had been 'none'.

关于css - 包含没有 "top"、 "right"、 "bottom"或 "left"的绝对定位元素的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19119748/

相关文章:

javascript - 停止绝对定位的 div 以在相对父级内移动

ios - 导航栏位置固定不适用于 IOS 设备

javascript - 在eBay上列出产品时无法显示图像

css - 格式化 CSS 时防止缩进

javascript - CSS 菜单仅在 IE 中隐藏在 flash 后面(SWFObject)

html - 如何正确地将我的 HTML 元素包含在其父 View 中?

r - 在同一位置绘制顶点

c# - 如何以编程方式在 Silverlight 中定位 Canvas ?

css - 使用 "position: static"作为图标的伪类 (CSS)

css - 为什么我的 Google 网络字体像素化?