Layoutlayoututilityabsolute
Absolute Center Box
Center-aligned box container fixed in viewport center.
Live Preview
Absolute Center Box
Usage
Copy and paste this code into your React component:
tsx
import { CenterFixedBox } from 'react-component-kit-ui/layout';
<CenterFixedBox>Content</CenterFixedBox>Manual Installation
If you are not using the npm package, create a new file and paste the following code: src/components/CenterFixedBox.tsx + CenterFixedBox.css:
CenterFixedBox.tsx
'use client';
import type { ReactNode } from 'react';
import './CenterFixedBox.css';
/**
* CenterFixedBox โ Absolute center box helper component.
*/
export interface CenterFixedBoxProps {
className?: string;
children?: ReactNode;
}
export function CenterFixedBox({ className = '',
children
}: CenterFixedBoxProps) {
return (
<>
<div className={`abs-center-container ${className}`} data-rk-bc4cce="">
<div className="abs-center" data-rk-bc4cce="">
{children ?? (<>
<div className="abs-card" data-rk-bc4cce="">
<h4 data-rk-bc4cce="">Centered Content</h4>
<p data-rk-bc4cce="">Centered cleanly in viewport or parent container.</p>
</div>
</>)}
</div>
</div>
</>
);
}
export default CenterFixedBox;CenterFixedBox.css
/* CenterFixedBox โ ported from astro-component-kit (layout/CenterFixedBox.astro) */
.abs-center-container:where([data-rk-bc4cce]) {
position: relative;
width: 100%;
min-height: 200px;
background: rgba(0, 0, 0, 0.2);
border-radius: var(--r-lg, 12px);
overflow: hidden;
border: 1px dashed rgb(var(--ink-rgb, 255 255 255) / 0.15);
}
.abs-center:where([data-rk-bc4cce]) {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: max-content;
}
.abs-card:where([data-rk-bc4cce]) {
padding: 1.25rem 2rem;
background: rgba(20, 20, 20, 0.85);
border: 1px solid rgb(var(--ink-rgb, 255 255 255) / 0.1);
border-radius: 12px;
text-align: center;
}
.abs-card:where([data-rk-bc4cce]) h4:where([data-rk-bc4cce]) {
margin: 0 0 0.25rem;
color: #fff;
}
.abs-card:where([data-rk-bc4cce]) p:where([data-rk-bc4cce]) {
margin: 0;
font-size: 0.85rem;
color: #94a3b8;
}Quick Info
- Category
- Layout
- Filename
CenterFixedBox.tsx- Dependencies
- None โ pure React + CSS
- Tags
- layoututilityabsolute