[英]Block Level Element vs Block Formatting Context
What is the difference between a HTML element that is a block level element and a HTML element that forms a block formatting context? 作为块级元素的HTML元素和形成块格式化上下文的HTML元素之间有什么区别?
Can a HTML element be both a block level element and form a block formatting context? HTML元素既可以是块级元素,也可以形成块格式化上下文?
Does being a block level element imply that it forms a block formatting context, or conversely, does forming a block formatting context imply that it must be a block level element? 作为块级元素是否意味着它形成块格式化上下文,或者相反,形成块格式化上下文是否意味着它必须是块级元素?
In a similar vein, how does this translate to inline elements and elements that form an inline formatting context? 同样,这如何转换为内联元素和形成内联格式上下文的元素?
(For some context, I've been trying to read Learn CSS Layout - The Pedantic Way but it's been a bit challenging to follow Chapter 1) (对于某些情况,我一直在尝试阅读学习CSS布局 - 迂腐之道,但遵循第1章有点挑战)
Note that this answer uses the term "box" in lieu of "element", as CSS makes a distinction between elements and boxes. 请注意,此答案使用术语“框”代替“元素”,因为CSS区分元素和框。 For the purposes of this answer, an HTML element is represented by a single box in CSS layout.
出于本答案的目的,HTML元素由CSS布局中的单个框表示。 In reality an element may generate any number of boxes (or none at all, as in
display: none
), but that's outside the scope of this question. 实际上,元素可以生成任意数量的框(或者根本没有框,如
display: none
),但这不在本问题的范围之内。
Can a HTML element be both a block level element and form a block formatting context?
HTML元素既可以是块级元素,也可以形成块格式化上下文?
Yes. 是。 The criteria in which a block box (ie a block-level block container box) may establish a BFC are stated in section 9.4.1 of CSS2.1, namely:
CSS2.1 第9.4.1节规定了块方框(即块级块容器盒)可以建立BFC的标准,即:
Does being a block level element imply that it forms a block formatting context, or conversely, does forming a block formatting context imply that it must be a block level element?
作为块级元素是否意味着它形成块格式化上下文,或者相反,形成块格式化上下文是否意味着它必须是块级元素?
Neither: 无论是:
display: block; overflow: visible; float: none; position: static
display: block; overflow: visible; float: none; position: static
display: block; overflow: visible; float: none; position: static
display: block; overflow: visible; float: none; position: static
(or position: relative
) does not establish a BFC. display: block; overflow: visible; float: none; position: static
(或position: relative
)不建立BFC。 In a similar vein, how does this translate to inline elements and elements that form an inline formatting context?
同样,这如何转换为内联元素和形成内联格式上下文的元素?
An inline box is an inline-level box whose contents participate directly in its parent's inline formatting context (see section 9.4.2 ). 内联框是一个内联级别的框,其内容直接参与其父级的内联格式化上下文(请参阅第9.4.2节 )。 Notably, the only boxes that can establish inline formatting contexts are block container boxes.
值得注意的是, 唯一可以建立内联格式化上下文的框是块容器框。
The difference between an inline box and an inline-block is that an inline-block's contents participate in the BFC that it establishes, not in the parent's IFC. 内联框和内联块之间的区别在于内联块的内容参与它建立的BFC,而不是父级的IFC。 Instead, only the inline-block itself participates in its parent's IFC.
相反,只有内联块本身参与其父级的IFC。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.