为什么固定和绝对定位的元素被认为是块格式化上下文,而不是相对定位的元素?
Why are fixed and absolute positioned elements considered block formatting context, but not a relatively positioned elements?
为什么固定和绝对定位的元素被视为块格式化上下文,而不是相对定位的元素?
简而言之,在 CSS 概念设计者的想法中是什么让绝对和固定定位元素成为 BFC 而相对元素不是?
我会说是因为 position:relative
不会像 absolute
那样改变元素的行为,而 fixed
会改变元素的行为。使用 absolute
和 fixed
设置元素时,它将从流中删除。这就像您删除了页面的一个片段以使其独立,因此需要建立一个新的块格式上下文。
和position:relative
不一样。
Once a box has been laid out according to the normal flow or floated, it may be shifted relative to this position. This is called relative positioning.
然后
A relatively positioned box keeps its normal flow size, including line breaks and the space originally reserved for it.ref
基本上,position:relative
将保持元素的行为,并且只允许您在放置在正常流中后移动其位置。您需要检查其他属性以查看该元素是否会建立 BFC。
您可能还注意到 positon:relative
适用于内联元素,内联元素不应建立 BFC。
为什么固定和绝对定位的元素被视为块格式化上下文,而不是相对定位的元素?
简而言之,在 CSS 概念设计者的想法中是什么让绝对和固定定位元素成为 BFC 而相对元素不是?
我会说是因为 position:relative
不会像 absolute
那样改变元素的行为,而 fixed
会改变元素的行为。使用 absolute
和 fixed
设置元素时,它将从流中删除。这就像您删除了页面的一个片段以使其独立,因此需要建立一个新的块格式上下文。
和position:relative
不一样。
Once a box has been laid out according to the normal flow or floated, it may be shifted relative to this position. This is called relative positioning.
然后
A relatively positioned box keeps its normal flow size, including line breaks and the space originally reserved for it.ref
基本上,position:relative
将保持元素的行为,并且只允许您在放置在正常流中后移动其位置。您需要检查其他属性以查看该元素是否会建立 BFC。
您可能还注意到 positon:relative
适用于内联元素,内联元素不应建立 BFC。