Positioned Layout Properties
wgpu-html implements CSS positioned layout with static, relative, absolute, and fixed positioning. The layout engine resolves containing blocks, applies offsets, and handles shrink-to-fit sizing for absolutely positioned elements.
position
Controls the positioning scheme:
position: static; /* normal flow (default) */
position: relative; /* offset from normal flow position */
position: absolute; /* removed from flow, positioned relative to containing block */
position: fixed; /* removed from flow, positioned relative to viewport */
All four values are fully supported. sticky is parsed but degrades to relative — scroll-pinning is not yet implemented.
Offsets: top, right, bottom, left
Offset properties work with positioned elements:
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
Accepted values: <length>, <percentage>, auto.
automeans no offset from that edge (default)- Percentages resolve against the containing block's size
Positioning Schemes
position: static (Default)
The element participates in normal flow layout. The top, right, bottom, left properties have no effect.
.static-box {
position: static; /* default, no offset applied */
width: 300px;
}
position: relative
The element stays in normal flow (occupies its original space), then is visually offset by top/right/bottom/left:
.shifted {
position: relative;
top: 10px; /* moves 10px down from normal position */
left: -5px; /* moves 5px left from normal position */
}
Normal flow position: [box]
Relative (top:10px; left:20px):
┌──────────────────┐
│ original space │
│ (still occupied) │
└──────────────────┘
┌───┐
│box│ (rendered here)
└───┘
The apply_relative_position() function in layout computes the offset and adds it to the element's position after normal flow layout.
position: absolute
The element is removed from normal flow (does not occupy space) and positioned relative to its containing block:
.container {
position: relative; /* creates containing block */
width: 400px;
height: 300px;
}
.absolute-badge {
position: absolute;
top: 0;
right: 0;
width: 80px;
height: 24px;
}
Container (position: relative)
┌──────────────────────────────┐
│ │
│ ┌───────┐ │ ← badge positioned
│ │ badge │ │ at top-right corner
│ └───────┘ │ of container
│ │
└──────────────────────────────┘