css1 formating model 在css2中分成了 box model 与 Visual formatting model
针对新概念
,这里用红字标出
Box model
The CSS box model describes the rectangular boxes that are generated for elements in the document tree and laid out according to the visual formatting model.
css盒模型,用来描述文档流中的矩形盒子,并根据可视化模型进行布局
1 Box dimensions -- 盒尺寸
Each box has a content area (e.g., text, an image, etc.) and optional surrounding padding, border, and margin areas; the size of each area is specified by properties defined below. The following diagram shows how these areas relate and the terminology used to refer to pieces of margin, border, and padding:
每一个盒子都由内容区域和可选择的padding border margin 组成,具体关系如图
The margin, border, and padding can be broken down into top, right, bottom, and left segments (e.g., in the diagram, "LM" for left margin, "RP" for right padding, "TB" for top border, etc.).
margin border padding 分为上下左右四段,具体关系如图所示
The perimeter of each of the four areas (content, padding, border, and margin) is called an "edge", so each box has four edges:
四个区域的周长
称之为边,故盒子由四种边
content edge or inner edge
The content edge surrounds the rectangle given by the width and height of the box, which often depend on the element's rendered content. The four content edges define the box's content box.
padding edge
The padding edge surrounds the box padding. If the padding has 0 width, the padding edge is the same as the content edge. The four padding edges define the box's padding box.
border edge
The border edge surrounds the box's border. If the border has 0 width, the border edge is the same as the padding edge. The four border edges define the box's border box.
margin edge or outer edge
The margin edge surrounds the box margin. If the margin has 0 width, the margin edge is the same as the border edge. The four margin edges define the box's margin box.
1.内容边 - 内边距
内容区域是宽高给定的矩形
,用来渲染元素的内容,其边定义了内容框
2.填(padding)边
填充区域的边,如果padding = 0,与内容边相同
3.边款(border)边
border的边,如果border = 0,与padding边相同
4.边缘(margin) - 外边距
margin的边,如果margin = 0,与border边相同
注:
在css1中只提到了内外边距,
Each edge may be broken down into a top, right, bottom, and left edge.
每个边分上下左右四个部分
The dimensions of the content area of a box — the content width and content height — depend on several factors: whether the element generating the box has the 'width' or 'height' property set, whether the box contains text or other boxes, whether the box is a table, etc. Box widths and heights are discussed in the chapter on visual formatting model details.
内容区域的宽高由以下几个因素决定
1.元素是否设置了宽高
即固定样式
2.盒子内是否有文本或其他盒子
无内容或文本的box,会进行折叠,除了修改css还可以通过 进行内容补充
3.盒子是否为table,等其他因素
特殊标签,特殊规则
详情在( visual formatting model)一章有描述
The background style of the content, padding, and border areas of a box is specified by the 'background' property of the generating element. Margin backgrounds are always transparent
内容 填充与边框的背景由background 属性决定,margin 的背景为透明
2 Example of margins, padding, and borders -- margin padding border 实例
略,整体上与css1更为详尽,且配图更完善
8.3 Margin properties: 'margin-top', 'margin-right', 'margin-bottom','margin-left', and 'margin'
行内元素margin-top/bottom 无效
其他略
吐槽
同样的在行内元素中使用line-height替代height(宽高无效),行内元素的本意是将文本(内容)一行行的显示出来,如果margin-top有效,他将会实现换行的效果,是内容不再是一行行
同理还有padding-top,虽然生效,但内容依然是一行行的显示,只是背景色可被渲染,在背景色统一的情况下,完全可以理解为不生效
4 Padding properties: 'padding-top', 'padding-right', 'padding-bottom','padding-left', and 'padding'
略
5 Border properties
略
6 The box model for inline elements in bidirectional context
介绍direction-- 文本读取顺序
吐槽
相对于css1中介绍的 Formatting model,box model 只保留了组成box的三大类属性
注入float,行内等概念都归为Visual formatting model