简体中文
<length>
用于表示距离尺寸的 CSS 数据类型。许多 CSS 属性会用到长度,比如 width、margin、padding。<percentage>
表述一个百分比值。许多 CSS 属性 可以取百分比值,用以根据父对象来确定大小。百分比值由一个<number>
具体数值后跟着%符号构成。就像其他在 css 里的单位一样,在%和数值之间是不允许有空格的。rpx
是一个以设备750px为基准的单位,750rpx即为屏幕宽度,375rpx即为屏幕一半宽度。它比较适合适配不同宽度的手机。但rpx的性能和精度不如px,如果px可满足需求,尽量使用px。名称 | Web | Android | iOS | 描述 |
---|---|---|---|---|
% | 4.0 | 3.9 | 4.11 | app平台仅width、height、padding(-)、margin(-)、top、left、right、bottom、flex-basis等属性支持 |
fr | 4.0 | x | x | |
px | 4.0 | 3.9 | 4.11 | |
rpx | 4.0 | 3.9 | 4.11 | |
em | 4.0 | 3.9 | 4.11 | |
rem | 4.0 | x | x | |
cap | 4.0 | x | x | |
ch | 4.0 | x | x | |
cm | 4.0 | x | x | |
cqb | 4.0 | x | x | |
cqh | 4.0 | x | x | |
cqi | 4.0 | x | x | |
cqmax | 4.0 | x | x | |
cqmin | 4.0 | x | x | |
cqw | 4.0 | x | x | |
dvb | 4.0 | x | x | |
dvh | 4.0 | x | x | |
dvi | 4.0 | x | x | |
dvw | 4.0 | x | x | |
ex | 4.0 | x | x | |
ic | 4.0 | x | x | |
in | 4.0 | x | x | |
lh | 4.0 | x | x | |
lvb | 4.0 | x | x | |
lvh | 4.0 | x | x | |
lvi | 4.0 | x | x | |
lvw | 4.0 | x | x | |
mm | 4.0 | x | x | |
pc | 4.0 | x | x | |
pt | 4.0 | x | x | |
q | 4.0 | x | x | |
rcap | 4.0 | x | x | |
rch | 4.0 | x | x | |
rex | 4.0 | x | x | |
ric | 4.0 | x | x | |
rlh | 4.0 | x | x | |
svb | 4.0 | x | x | |
svh | 4.0 | x | x | |
svi | 4.0 | x | x | |
svw | 4.0 | x | x | |
vb | 4.0 | x | x | |
vh | 4.0 | x | x | |
vi | 4.0 | x | x | |
vmax | 4.0 | x | x | |
vmin | 4.0 | x | x | |
vw | 4.0 | x | x |
注意
长度默认值差异
<length>
可以不设置单位,不设置单位时当做 px 处理<length>
必须设置单位,不设置单位时当做无效值处理 <length>
指定明确单位。单位精度差异
0.5px
很难正常显示。但app可以正常显示。rpx
和百分比
,比px
更容易产生浮点数,所以如果px能满足需求,尽量不用rpx和百分比。性能差异
名称 | Web | Android | iOS | 描述 |
---|---|---|---|---|
px | 4.0 | 3.9 | 4.11 | |
rpx | 4.0 | 3.9 | 4.11 | |
em | 4.0 | 3.9 | 4.11 | app平台仅line-height属性支持 |
rem | 4.0 | x | x | |
cap | 4.0 | x | x | |
ch | 4.0 | x | x | |
cm | 4.0 | x | x | |
cqb | 4.0 | x | x | |
cqh | 4.0 | x | x | |
cqi | 4.0 | x | x | |
cqmax | 4.0 | x | x | |
cqmin | 4.0 | x | x | |
cqw | 4.0 | x | x | |
dvb | 4.0 | x | x | |
dvh | 4.0 | x | x | |
dvi | 4.0 | x | x | |
dvw | 4.0 | x | x | |
ex | 4.0 | x | x | |
ic | 4.0 | x | x | |
in | 4.0 | x | x | |
lh | 4.0 | x | x | |
lvb | 4.0 | x | x | |
lvh | 4.0 | x | x | |
lvi | 4.0 | x | x | |
lvw | 4.0 | x | x | |
mm | 4.0 | x | x | |
pc | 4.0 | x | x | |
pt | 4.0 | x | x | |
q | 4.0 | x | x | |
rcap | 4.0 | x | x | |
rch | 4.0 | x | x | |
rex | 4.0 | x | x | |
ric | 4.0 | x | x | |
rlh | 4.0 | x | x | |
svb | 4.0 | x | x | |
svh | 4.0 | x | x | |
svi | 4.0 | x | x | |
svw | 4.0 | x | x | |
vb | 4.0 | x | x | |
vh | 4.0 | x | x | |
vi | 4.0 | x | x | |
vmax | 4.0 | x | x | |
vmin | 4.0 | x | x | |
vw | 4.0 | x | x |