AbsoluteCenter
Centers an element over its parent, on one axis or both, without changing the parent's layout.
Centered content
Usage
The parent must have position: relative.
import { AbsoluteCenter, Box } from '@leverui/components';
export function AbsoluteCenterUsage() {
return (
<Box class="absolute-center-usage-panel">
<AbsoluteCenter>Centered Content</AbsoluteCenter>
</Box>
);
}
/* absolute-center-usage.css */
.absolute-center-usage-panel {
position: relative;
height: 100px;
background: var(--leverui-colors-bg-muted);
}
Examples
Axis Control
Control which axis to center on using the axis prop. Options are horizontal, vertical, or both (default).
<AbsoluteCenter axis="horizontal" />
horizontal
<AbsoluteCenter axis="vertical" />
vertical
<AbsoluteCenter axis="both" />
both
With Content
Use AbsoluteCenter with content such as icons, badges, and status indicators.
Overlay Usage
Create a loading overlay or modal-like content centered over existing content.
RTL Support
AbsoluteCenter also centers content in right-to-left layouts.
RTL (horizontal)
البداية
RTL (vertical)
البداية
RTL (both)
البداية
Props
| Prop | Default | Type | Description |
|---|---|---|---|
axis | 'both' | 'horizontal' | 'vertical' | 'both' | Direction to center in. |
as | div | Native HTML tag | HTML tag to render. |
asChild | — | Render callback | Render your own element. |
unstyled | false | Boolean | Turn off the default position. |
Style with class, style, .leverui-absolute-center, or the data-axis
attribute. No css prop.