为什么绝对位置元素基于其父的右边界? [英] Why does an absolute position element wrap based on its parent's right bound?

查看:103
本文介绍了为什么绝对位置元素基于其父的右边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一个绝对定位的元素依赖于它的父文本包装? position:absolute 从流中删除元素?

Why does an absolutely positioned element depend on its parent for text wrapping? Doesn't position: absolute remove an element from the flow?

我想要删除此边界。这就像一个隐含的 max-width ,我不想要;我想另一个开发人员能够设置这个 max-width ,不担心这个任意边界。如何删除此行为?

I'm looking to remove this boundary. This is like an implied max-width that I don't want; I want another developer to be able to set this max-width, and not worry about this arbitrary bound. How do I remove this behavior?

为方便起见,此处是一个jsbin

推荐答案


不会 :absolute 从流中删除一个元素?

Doesn't position: absolute remove an element from the flow?

这与流无关。元素的宽度始终遵守其包含块。如果元素是绝对定位的,那么它的尺寸可以被 top right 底部,但只要其 width auto ,那么它必须仍然被限制到它的包含块的宽度(使它在这方面没有不同于流中块框),在你的情况下,它是绝对定位的父。没有真正的任何其他元素的约束,绝对定位的元素可以自己的大小本身相对于而不妥协其文本的流。

This has nothing to do with the flow. The width of an element always respects its containing block. If the element is absolutely positioned, then its dimensions can be constrained by top, right, bottom and left, but as long as its width is auto then it must still be constrained to the width of its containing block (making it no different from in-flow block boxes in that respect), which in your case is its absolutely-positioned parent. There isn't really any other element whose constraints the absolutely-positioned element could size itself with respect to without compromising the flow of its text.

有关如何宽度,请参阅规格

For the specifics of how this width is calculated, refer to the spec.

这篇关于为什么绝对位置元素基于其父的右边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆