欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

padding 百分比宽度

shiping1 的头像

padding-width的取值

  • <length>: 长度表示法
  • <percentage>: 百分比表示法,padding百分比的计算是基于生成的框的包含块的宽度,不是基于高度
  • auto: 自动
来自 http://www.dreamdu.com/css/property_padding/



CSS中margin-top/bottom(padding-top/bottom)百分比为何以最近的块级祖先元素的宽度而不是高度作计算?

CSS2.1 Box model
The percentage is calculated with respect to the width of the generated box's containing block. Note that this is true for 'margin-top' and 'margin-bottom' as well.
margin:百分比的计算基于生成框的包含块的宽度(margin-top/bottom也是如此)。
padding与之类似。

margin-top的计算值为何不相对于 containing block height?唯一能想出来的原因是margin-top值增大会撑开父容器的height,导致循环计算。但,margin-top值的percent相对于 containing block width有什么意义?出于什么原因要这样设计?因为如果仅仅因为循环计算的原因,我觉得也可以用变通的方式来实现,比如:要求父容器固定高度时,margin-top百分比值生效,父容器不固定大小时,margin-top 百分比值不生效!
按票数排序按时间排序

2 个回答

普通分类: