Phase 9: Advanced Layout#
Implement the box-sizing CSS property (content-box and border-box).
Current State#
- Layout always uses
content-boxbehavior:width/heightapply to the content area only box-sizingis not parsed or resolved in computed styles- The UA stylesheet does not set
box-sizing(browsers default tocontent-box, but many sites usebox-sizing: border-boxvia reset stylesheets)
Requirements#
- Parse
box-sizingincss/values.rsorstyle/computed.rs:content-box(default):width/heightset the content area size; padding and border are added outsideborder-box:width/heightinclude padding and border; content area shrinks to fit
- Resolve in computed styles: Add
box_sizingfield toComputedStyle - Apply in layout: When
box-sizing: border-box, subtract padding and border from the specifiedwidth/heightto get the content area dimensions. Clamp content size to 0 if padding+border exceeds specified size. - Inherit:
box-sizingis NOT inherited (per spec)
Files to Modify#
crates/style/src/computed.rs— AddBoxSizingenum, resolve from CSS valuecrates/layout/src/lib.rs— Adjust width/height computation whenborder-box
Tests#
box-sizing: content-box(default): width applies to content onlybox-sizing: border-box: width includes padding and borderborder-boxwith padding larger than width: content area clamps to 0- Verify
box-sizingis not inherited
Acceptance Criteria#
box-sizing: content-boxandborder-boxboth work correctly- Layout correctly adjusts content dimensions for border-box
- All tests pass, clippy clean, fmt clean