Phase 9: Advanced Layout#
Implement CSS float and clear properties for flowing content around floated elements.
Current State#
floatandclearproperties are NOT parsed in computed styles- Layout only supports normal block and inline flow
- No float tracking or line-shortening logic exists
Requirements#
- Parse
float:none(default),left,right - Parse
clear:none(default),left,right,both - Float layout:
- Floated elements are removed from normal flow
float: leftelements are placed at the left edge of the containing blockfloat: rightelements are placed at the right edge- Subsequent floats stack horizontally (or drop below if insufficient space)
- Floats do not extend outside their containing block
- Line box shortening: Inline content flows around floats — line boxes are shortened to avoid overlapping floated elements
- Clear: An element with
clear: leftmoves below all preceding left floats.clear: rightbelow right floats.clear: bothbelow all floats. - Containing floats: A block formatting context (overflow != visible, floats, etc.) must expand to contain its floated children ("clearfix" behavior)
- Float stacking: Multiple floats of the same direction stack horizontally, wrapping to the next line when they exceed container width
Files to Modify#
crates/style/src/computed.rs— AddFloatandClearenums, parse from CSS values, add toComputedStylecrates/layout/src/lib.rs— Major changes: track float positions, implement line-shortening for inline layout, handle clear, expand BFC to contain floats
Tests#
float: leftelement is positioned at left edge, content wraps around itfloat: rightelement is positioned at right edge- Two left floats stack horizontally
clear: bothmoves element below all floats- Containing block expands to enclose floated children (BFC containment)
- Inline text wraps around a floated element
Acceptance Criteria#
float: leftandfloat: rightposition elements correctly- Inline content flows around floats
clearproperty works correctly- BFC containers expand to contain floats
- All tests pass, clippy clean, fmt clean