BetaThis is a live doc! Anyone with edit access can make updates in real time without having to publish.
尺寸百分比

绝大部分可以书写尺寸的地方,都可以书写百分比

百分比是一个相对单位,通常其相对于元素的参考系,比如:

  • 普通元素的参考系为父元素的 content 区域

  • 绝对(固定)定位元素的参考系为父元素中第一个定位元素(relative / viewport)的 content+padding 区域

常见的百分比情况

css 属性

百分比相对于

备注

width

参考系的宽度


height

参考系的高度

参考系高度未确定(受子元素影响)时,设置无效

margin / padding

参考系的宽度

无论方向,均为宽度

border

不可以使用百分比


border-radius

元素本身的四边