Convert between viewport units and pixels: vw and vh are 1% of the viewport width and height, handy for full-screen layouts.
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Viewport percentage | 1vw is one percent of viewport width, 1vh of height | CSS Values and Units Level 4 |
| Mobile viewport height | browser chrome makes 100vh overflow, so use svh, lvh or dvh | CSS Values and Units Level 4 |
| Extreme units | vmin follows the shorter axis and vmax the longer | CSS Values and Units Level 4 |
| 设备 | 宽度(px) | 典型 vw 示例 |
|---|---|---|
| 手机 | 360–414 | 100vw ≈ 360–414px |
| 平板 | 768–1024 | 50vw ≈ 384–512px |
| 笔记本 | 1280–1440 | 50vw ≈ 640–720px |
| 桌面 | 1920 | 50vw = 960px |
换算公式:vw = px ÷ 视口宽度 × 100;px = vw ÷ 100 × 视口宽度(vh 同理用高度)。
输入:50vw、视口宽 1280。
处理:相乘。
输出:640px;随视口变。
设计稿标注、配色与排版相关的快速参考。