visual formatting model details简译 <一> 之 Containing box的定义

如果要计算一个box的位置以及宽高,那么必须知道它的containing box,然后才能在containing box的基础上计算出box的位置、宽高。选取containing box的方法是固定的,具体如下:

1)文档根节点的containing box也被称为initial containing box。Initial containing box是以文档左上角作为原点,view-port的宽高作为自己宽高的矩形框。

2)其他in-flow box的containing box是距离自己最近的、作为容器的block box的content边界。

3)fixed box的containing box就是窗口的view-port,没有固定位置。因此,fixed box永远可见,也会随着滚动条滚动。

4)absolute box的containing box与距离自己最近的absolute、fixed、relative祖先的box有关。如果这个祖先是inline结点,那么containing box是第一个child box 的padding边界与最后一个child box 的padding边界做并运算得到的。如果这个祖先是block节点,那么containing box就是祖先的block box的padding边界。如果absolute box不存在absolute、fixed、relative祖先,那么absolute box的containing box就是initial containing box。

如下的html代码。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
  <HEAD>
    <TITLE>Illustration of containing blocks</TITLE>
  </HEAD>
  <BODY id="body">
    <DIV id="div1">
    <P id="p1">This is text in the first paragraph...</P>
    <P id="p2">This is text <EM id="em1"> in the 
    <STRONG id="strong1">second</STRONG> paragraph.</EM></P>
    </DIV>
  </BODY>
</HTML>

这段代码中box,containing box的对应规则如下表所示。

Box对应的文档结点Containing box对应的文档结点
HTMLinitial containing box
bodyhtml
div1body
p1div1
p2div1
emp2
strongp2


如果这个网页增加一条css规则

#div1 { position: absolute; left: 50px; top: 50px }

那么box, containing box的对应规则变为,

Box对应的文档结点Containing box对应的文档结点
HTMLinitial containing box
bodyhtml
div1initial containing box
p1div1
p2div1
emp2
strongp2


如果再增加一条css规则,

#em1 { position: absolute; left: 100px; top: 100px }

Box对应的文档结点Containing box对应的文档结点
HTMLinitial containing box
bodyhtml
div1initial containing box
p1div1
p2div1
emdiv1
strongem

对上表需要多做一些解释。原本EM是inline 结点,它的box也是inline box。在em被设置为abolute之后,它就变为了block box。
css2.1标准中描述了 display、position、float三个属性值会彼此影响。具体来说有3条规则:1)如果display属性值为none,那么position、float不发挥作用; 2)如果规则1不满足且position属性值为absolute、fixed,那么float属性值被作为none, display属性值按照最下面的表发生变化; 3)如果规则1、规则2都不满足且float属性值不是none,那么display属性值按照最下面的表发生变化。
display属性的变换规则
原值新值
inline-tabletable
Inline, table-row-group, table-column, table-column-group, table-header-group,table-footer-group, table-row, table-cell, table-caption, inline-blockBlock
其他不变

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值