css2 - Box model

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)系如圖

boxdim.png

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市缕探,隨后出現(xiàn)的幾起案子波闹,更是在濱河造成了極大的恐慌,老刑警劉巖娶耍,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件失球,死亡現(xiàn)場(chǎng)離奇詭異邮丰,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)轴咱,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門既忆,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人嗦玖,你說(shuō)我怎么就攤上這事患雇。” “怎么了宇挫?”我有些...
    開(kāi)封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵苛吱,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我器瘪,道長(zhǎng)翠储,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任橡疼,我火速辦了婚禮援所,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘欣除。我一直安慰自己住拭,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著滔岳,像睡著了一般杠娱。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上谱煤,一...
    開(kāi)封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天摊求,我揣著相機(jī)與錄音,去河邊找鬼刘离。 笑死室叉,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的硫惕。 我是一名探鬼主播茧痕,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼疲憋!你這毒婦竟也來(lái)了凿渊?” 一聲冷哼從身側(cè)響起梁只,我...
    開(kāi)封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤缚柳,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后搪锣,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體秋忙,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年构舟,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了灰追。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡狗超,死狀恐怖弹澎,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情努咐,我是刑警寧澤苦蒿,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布,位于F島的核電站渗稍,受9級(jí)特大地震影響佩迟,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜竿屹,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一报强、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧拱燃,春花似錦秉溉、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)夯膀。三九已至,卻和暖如春苍蔬,著一層夾襖步出監(jiān)牢的瞬間诱建,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工碟绑, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留俺猿,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓格仲,卻偏偏與公主長(zhǎng)得像押袍,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子凯肋,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容