Units and Sizing
Choose responsive units and control intrinsic, minimum, and maximum sizes.
CSS offers absolute, font-relative, viewport, container, and percentage units. Choose the unit that matches the relationship you are expressing.
Match units to intent
units.css
body { font-size: 1rem; }
.article { max-width: 68ch; }
.hero { min-height: 70svh; }
.icon { width: 1.25em; height: 1.25em; }
.card { padding: clamp(1rem, 4cqi, 2rem); }
Use rem for user-scalable system sizes, em for local relationships, ch for text measure, and small viewport units when mobile browser chrome matters. Container units respond to a query container.
Intrinsic sizing
intrinsic.css
.button { width: fit-content; }
.grid { grid-template-columns: max-content minmax(0, 1fr); }
img { width: 100%; height: auto; }
min-content, max-content, and fit-content let content participate in sizing. Set min-width: 0 on flexible children that must shrink around long text.
Keep this
Use relative units for adaptable relationships, constrain line length, and let intrinsic sizing handle content before forcing dimensions.
学习位置已保存在此设备上。