Box model

20
Box model wenjuli( 李李李 )

Transcript of Box model

Page 1: Box model

Box model wenjuli( 李文举 )

Page 2: Box 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.”

Page 3: Box model
Page 4: Box model

如何创建「

宽度为 100% ,有左右

padding 、有 border 的文本

框」?

作者
宽度由父级限制高度由内容决定
Page 5: Box model

- 嵌套 (IE6+) -

Page 6: Box model
Page 7: Box model

- box-sizing (IE8+) -

Page 8: Box model

– 8.3.1 Collapsing margins

“In CSS, the adjoining margins of two or more boxes (which might or might not be

siblings) can combine to form a single margin. Margins that combine this way are

said to collapse, and the resulting combined margin is called a collapsed

margin.”

Page 9: Box model

Adjoining vertical margins collapse.

Horizontal margins never collapse.

Page 10: Box model

• Adjoining (毗邻)

• both belong to in-flow block-level boxes that participate in the same block formatting context

• no line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for this purpose.)

• both belong to vertically-adjacent box edges, i.e. form one of the following pairs:(4种 )

Page 11: Box model

• contd.

• top margin of a box and top margin of its first in-flow child

• bottom margin of box and top margin of its next in-flow following sibling

• bottom margin of a last in-flow child and bottom margin of its parent if the parent has 'auto' computed height

• top and bottom margins of a box that does not establish a new block formatting context and that has zero computed 'min-height', zero or 'auto' computed 'height', and no in-flow children

Page 12: Box model
Page 13: Box model
Page 14: Box model

无 :before 有 :before

overflow:hidde

n

Page 15: Box model

问: clearfix中添加 :before有什么好处?

答:

① 避免 top-margin collapse ,与其他生成 bfc的技术保持视觉一致,如 overflow:hidden;

② 与 IE6/7 的视觉保持一致,因为设置了zoom:1 ,触发 haslayout , top-margin 是不collapse 的。

Page 16: Box model

– Padding properties: <percentage>

“The percentage is calculated with respect to the width of the generated box's

containing block, even for 'padding-top' and 'padding-bottom'. ”

Page 17: Box model

Responsive background images with fixed or fluid aspect ratios

Page 18: Box model
Page 19: Box model
Page 20: Box model

射射!