CSS 尺寸单位(px rem em vh)
界面字号阶梯优先 rem;必须时再用 px 画细边框。
| 单位 | 相对什么 | 典型用途 |
|---|---|---|
| px | Device pixel (CSS pixel) | Borders, precise icons |
| rem | Root element font-size | Type scale, spacing |
| em | Parent font-size | Component-local sizing |
| % | Parent property | Widths, flexible layouts |
| vw | 1% viewport width | Full-bleed sections |
| vh | 1% viewport height | Hero height (mind mobile UI) |
| vmin / vmax | Smaller/larger viewport side | Square-ish responsive sizing |
| ch | Width of “0” glyph | Code blocks, monospace fields |
| ex | x-height of font | Rare fine typography |
| svh / lvh / dvh | Small/large/dynamic viewport | Mobile browser chrome-safe height |
ملاحظات
- 移动端 100vh 可能含被隐藏的浏览器栏,支持时优先 dvh/svh。
- 用户字体大小会影响 rem,这对无障碍通常是好事。