CSS 单位转换指南
CSS 中有多种长度单位,理解它们之间的转换关系对前端开发至关重要。单位分为绝对单位和相对单位两大类。
绝对单位:
- px:像素,最常用的绝对单位
- pt:点,1pt = 1/72 英寸,常用于打印
- cm/mm/in:厘米/毫米/英寸,物理单位
相对单位:
- rem:相对于根元素字体大小,1rem = 根元素 font-size
- em:相对于当前元素字体大小
- vw/vh:相对于视口宽度/高度的 1%
- %:相对于父元素的对应属性值
本工具默认基准字体大小为 16px(浏览器默认值),可根据实际项目配置调整。
CSS Unit Conversion Guide
CSS has multiple length units. Understanding their conversion relationships is essential for frontend development. Units are divided into absolute and relative categories.
Absolute units:
- px — Pixels, the most commonly used absolute unit
- pt — Points, 1pt = 1/72 inch, commonly used in print
- cm/mm/in — Centimeters/millimeters/inches, physical units
Relative units:
- rem — Relative to root element font size, 1rem = root font-size
- em — Relative to current element font size
- vw/vh — 1% of viewport width/height
- % — Relative to parent element's corresponding property value
This tool defaults to a 16px base font size (browser default). Adjust as needed for your project.