Box model
-
Upload
lee-jace -
Category
Technology
-
view
53 -
download
1
Transcript of Box model
![Page 1: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/1.jpg)
Box model wenjuli( 李文举 )
![Page 2: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/2.jpg)
- 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](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/3.jpg)
![Page 4: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/4.jpg)
如何创建「
宽度为 100% ,有左右
padding 、有 border 的文本
框」?
![Page 5: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/5.jpg)
- 嵌套 (IE6+) -
![Page 6: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/6.jpg)
![Page 7: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/7.jpg)
- box-sizing (IE8+) -
![Page 8: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/8.jpg)
– 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](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/9.jpg)
Adjoining vertical margins collapse.
Horizontal margins never collapse.
![Page 10: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/10.jpg)
• 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](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/11.jpg)
• 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](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/12.jpg)
![Page 13: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/13.jpg)
![Page 14: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/14.jpg)
无 :before 有 :before
overflow:hidde
n
![Page 15: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/15.jpg)
问: clearfix中添加 :before有什么好处?
答:
① 避免 top-margin collapse ,与其他生成 bfc的技术保持视觉一致,如 overflow:hidden;
② 与 IE6/7 的视觉保持一致,因为设置了zoom:1 ,触发 haslayout , top-margin 是不collapse 的。
![Page 16: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/16.jpg)
– 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 18: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/18.jpg)
![Page 19: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/19.jpg)
![Page 20: Box model](https://reader036.fdocument.pub/reader036/viewer/2022081519/55b79d7abb61eb8c558b47c8/html5/thumbnails/20.jpg)
射射!