CSS UNITS
屏幕单位换算,px rem em 一秒通。
在 px、rem、em、pt、% 之间即时互转,可设根字号与视口宽度,并附常用参考表,前端切图与移动端适配更顺手。纯前端本地处理。
常用参考表(根字号 16px)
单位换算怎么算?
rem 相对根字号(默认 16px),em 相对当前字号(此处按根字号估算),pt 是印刷点(1px = 0.75pt),% 在宽度场景下相对视口(1vw = 视口宽/100)。改上面任意值,下方结果实时联动。
示例与注意事项Example & notes
一个例子A worked example
设计稿 375px 宽、按钮宽 88px:根字号 16px 时等于 23.4375rem,页面同时给出 vw 与百分比换算。A design at 375 px with an 88 px button equals 23.4375 rem at a 16 px root; vw and percentage values are given too.
注意事项Things to watch
- rem 随根字号变化、vw 随视口变化,移动端适配常用 vw 或 clamp。rem follows the root font size, vw follows the viewport — mobile layouts usually want vw or clamp.
- 百分比是相对父元素而不是视口,误用会导致宽度意外。Percentages are relative to the parent, not the viewport, which surprises people.
- 换算只解决起点,断点处仍需人工微调。Conversion gives a starting point; breakpoints still need manual tuning.
- 1rem 等于根元素字号而不是父元素字号,改动 html 字号会影响全站,调优前先锁定根字号。1 rem tracks the root font size rather than the parent, so changing it shifts the whole site — lock it before tuning.
相关问答More Q&A
该选 rem 还是 vw?rem or vw — which one?
需要跟随用户字号缩放用 rem;需要严格按设计比例铺满用 vw。Use rem when text must respect user font settings, vw when the layout must scale with the viewport.
支持小程序 rpx 吗?Does it support rpx?
支持,按 750 设计稿的换算规则给出 rpx 值。Yes — rpx values follow the standard 750-unit design width.