css1 formating model 在css2中分成了 box model 與 Visual formatting model
針對(duì)新概念
,這里用紅字標(biāo)出
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盒模型,用來(lái)描述文檔流中的矩形盒子,并根據(jù)可視化模型進(jìn)行布局
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:
每一個(gè)盒子都由內(nèi)容區(qū)域和可選擇的padding border margin 組成,具體關(guān)系如圖
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 分為上下左右四段,具體關(guān)系如圖所示
The perimeter of each of the four areas (content, padding, border, and margin) is called an "edge", so each box has four edges:
四個(gè)區(qū)域的周長(zhǎng)
稱之為邊,故盒子由四種邊
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.內(nèi)容邊 - 內(nèi)邊距
內(nèi)容區(qū)域是寬高給定的矩形
,用來(lái)渲染元素的內(nèi)容,其邊定義了內(nèi)容框
2.填(padding)邊
填充區(qū)域的邊,如果padding = 0,與內(nèi)容邊相同
3.邊款(border)邊
border的邊,如果border = 0,與padding邊相同
4.邊緣(margin) - 外邊距
margin的邊,如果margin = 0,與border邊相同
注:
在css1中只提到了內(nèi)外邊距,
Each edge may be broken down into a top, right, bottom, and left edge.
每個(gè)邊分上下左右四個(gè)部分
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.
內(nèi)容區(qū)域的寬高由以下幾個(gè)因素決定
1.元素是否設(shè)置了寬高
即固定樣式
2.盒子內(nèi)是否有文本或其他盒子
無(wú)內(nèi)容或文本的box,會(huì)進(jìn)行折疊,除了修改css還可以通過(guò)?進(jìn)行內(nèi)容補(bǔ)充
3.盒子是否為table,等其他因素
特殊標(biāo)簽,特殊規(guī)則
詳情在( 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
內(nèi)容 填充與邊框的背景由background 屬性決定,margin 的背景為透明
2 Example of margins, padding, and borders -- margin padding border 實(shí)例
略,整體上與css1更為詳盡,且配圖更完善
8.3 Margin properties: 'margin-top', 'margin-right', 'margin-bottom','margin-left', and 'margin'
行內(nèi)元素margin-top/bottom 無(wú)效
其他略
吐槽
同樣的在行內(nèi)元素中使用line-height替代height(寬高無(wú)效),行內(nèi)元素的本意是將文本(內(nèi)容)一行行的顯示出來(lái),如果margin-top有效,他將會(huì)實(shí)現(xiàn)換行的效果,是內(nèi)容不再是一行行
同理還有padding-top,雖然生效,但內(nèi)容依然是一行行的顯示,只是背景色可被渲染,在背景色統(tǒng)一的情況下,完全可以理解為不生效
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-- 文本讀取順序
吐槽
相對(duì)于css1中介紹的 Formatting model,box model 只保留了組成box的三大類屬性
注入float,行內(nèi)等概念都?xì)w為Visual formatting model