|
| 1 | +# position Property Visual Reference |
| 2 | + |
| 3 | +The `position` property controls how an element is positioned within its container. FlexRender supports three positioning modes matching CSS behavior: `static` (default), `relative`, and `absolute`. |
| 4 | + |
| 5 | +## Position Modes |
| 6 | + |
| 7 | +### static (default) |
| 8 | +Element follows normal flex flow. No offset properties are applied. |
| 9 | + |
| 10 | +### relative |
| 11 | +Element is offset from its normal flow position. Siblings are not affected. |
| 12 | + |
| 13 | +| Example | Description | Visual | |
| 14 | +|---------|-------------|--------| |
| 15 | +| Offset | Middle box shifted with `top: 15, left: 20` from normal position |  | |
| 16 | + |
| 17 | +### absolute |
| 18 | +Element is removed from flex flow and positioned relative to its containing flex parent's padding box. |
| 19 | + |
| 20 | +| Example | Description | Visual | |
| 21 | +|---------|-------------|--------| |
| 22 | +| Top/Left | Box pinned to `top: 10, left: 10` |  | |
| 23 | +| Bottom/Right | Box pinned to `bottom: 10, right: 10` |  | |
| 24 | +| Centered | Box centered via equal insets on all sides |  | |
| 25 | +| Flow Exclusion | Absolute elements excluded from flex flow — A, C, D stack normally |  | |
| 26 | +| Inset Sizing | Width/height computed from opposing insets (no explicit size) |  | |
| 27 | + |
| 28 | +## Practical Patterns |
| 29 | + |
| 30 | +| Pattern | Description | Visual | |
| 31 | +|---------|-------------|--------| |
| 32 | +| Badge | Star badge overlaid on product card with `top: 8, right: 8` |  | |
| 33 | +| Text Overlay | Dark bar with text at bottom of image using `bottom: 0, left: 0, right: 0` |  | |
| 34 | +| Floating Label | Input label floats above border with `top: -8, left: 12` |  | |
| 35 | + |
| 36 | +## Code Examples |
| 37 | + |
| 38 | +### YAML Template |
| 39 | + |
| 40 | +```yaml |
| 41 | +# Badge pattern — star overlay on card |
| 42 | +- type: flex |
| 43 | + overflow: hidden |
| 44 | + children: |
| 45 | + - type: image |
| 46 | + src: "product.png" |
| 47 | + fit: cover |
| 48 | + - type: image |
| 49 | + position: absolute |
| 50 | + top: "8" |
| 51 | + right: "8" |
| 52 | + src: "star-badge.png" |
| 53 | + width: "24" |
| 54 | + height: "24" |
| 55 | +``` |
| 56 | +
|
| 57 | +### AST (C# Code) |
| 58 | +
|
| 59 | +```csharp |
| 60 | +using FlexRender.Layout; |
| 61 | +using FlexRender.Parsing.Ast; |
| 62 | + |
| 63 | +var container = new FlexElement |
| 64 | +{ |
| 65 | + Width = "300", Height = "200", |
| 66 | + Overflow = Overflow.Hidden |
| 67 | +}; |
| 68 | + |
| 69 | +// Absolute badge in top-right corner |
| 70 | +container.AddChild(new FlexElement |
| 71 | +{ |
| 72 | + Position = Position.Absolute, |
| 73 | + Top = "8", Right = "8", |
| 74 | + Width = "24", Height = "24", |
| 75 | + Background = "#e74c3c" |
| 76 | +}); |
| 77 | +``` |
| 78 | + |
| 79 | +## Inset Properties |
| 80 | + |
| 81 | +| Property | Type | Description | |
| 82 | +|----------|------|-------------| |
| 83 | +| `top` | string | Offset from top edge of containing block's padding box | |
| 84 | +| `right` | string | Offset from right edge | |
| 85 | +| `bottom` | string | Offset from bottom edge | |
| 86 | +| `left` | string | Offset from left edge | |
| 87 | + |
| 88 | +**Priority rules:** |
| 89 | +- `left` takes priority over `right` when both are specified (for `position: relative`) |
| 90 | +- `top` takes priority over `bottom` when both are specified (for `position: relative`) |
| 91 | +- For `position: absolute`, opposing insets (`left` + `right` or `top` + `bottom`) without explicit size compute the element's width/height (inset sizing) |
| 92 | + |
| 93 | +## Notes |
| 94 | + |
| 95 | +- Absolute elements are excluded from flex flow — siblings layout as if the absolute element doesn't exist |
| 96 | +- Absolute elements are excluded from intrinsic measurement — parent sizing ignores them |
| 97 | +- Relative positioning does not affect sibling positions — space is reserved at the original position |
| 98 | +- When no insets are specified on an absolute element, it defaults to `justify-content` (main axis) and `align-items` (cross axis) fallback positioning |
| 99 | +- Inset values support pixels, percentages, and em units |
| 100 | +- Use `overflow: hidden` on the parent to clip overflowing absolute elements |
| 101 | + |
| 102 | +## See Also |
| 103 | + |
| 104 | +- [[Flexbox-Layout]] - Complete flexbox layout reference |
| 105 | +- [[Element-Reference]] - All element types and properties |
| 106 | +- [[Visual-Reference]] - Index of all visual documentation pages |
0 commit comments