简体   繁体   English

“块框”和“块级元素”有什么区别?

[英]What is the difference between "block box" and "block-level element"?

This MDN doc says: 这个 MDN 文档说:

In CSS we broadly have two types of boxes - block boxes and inline boxes.在 CSS 中,我们大致有两种类型的框 - 块框和行内框。

But in this MDN doc that talks about normal flow, block boxes are never mentioned.但是在这个谈论正常流程的 MDN 文档中,从未提及块框。 Only block-level elements are mentioned.仅提及块级元素。

What is the difference?有什么区别?

Block vs Block-Level块与块级

Lots.很多。 Block boxes are both block-level and also block containers.块盒既是块级的,也是块容器。 That's display:block , display:flow-root , the principal box of display:list-item and the table wrapper box of display:table .那就是display:blockdisplay:flow-rootdisplay:list-item的主体框和 display: display:table的表格包装框。

Boxes that are block-level, but not block containers, and therefore not block boxes are those which have eg display:flex , display:grid and the table grid box of display:table块级的框,但不是块容器,因此不是块框是那些具有例如display:flexdisplay:griddisplay:table的表格网格框的框

Boxes that are block containers, but not block-level, and therefore not block boxes are those which have eg display:inline-block and display:table-cell .是块容器但不是块级别的框,因此不是块框是那些具有例如display:inline-blockdisplay:table-cell的框。

Stating that there are broadly two types of boxes - block and inline - is at best misleading, if not outright wrong.声明大致有两种类型的盒子——块和内联——充其量是误导,如果不是完全错误的话。 We could better say that there are broadly two types of boxes - block-level and inline-level, but even then, only broadly .我们最好说大致上有两种类型的盒子——块级和内联级,但即便如此,也只是广义上的。 Block-level boxes are participants in a Block Formatting Context.块级框是块格式化上下文的参与者。 Inline-level boxes are participants in an Inline Formatting Context.行内级框是行内格式化上下文的参与者。 Boxes that are participants in other formatting contexts, such as flex items, grid items, and some of the internal table and ruby boxes are neither.参与其他格式化上下文的框,例如弹性项、网格项和一些内部表和 ruby 框都不是。

Elements vs Boxes元素与盒子

Elements are objects of SGML, HTML and DOM.元素是SGML、HTML和DOM的对象。 Boxes are objects of CSS. A block-level element is one that when the CSS box tree is being formed, by default generates at least a principal box which is block-level.框是CSS的对象。块级元素是在形成CSS框树时,默认至少生成一个块级的主框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM