Макеты и Сетки layoututilityabsolute
Absolute Center Box
Точно центрированный блок по осям экрана с ограничением ширины.
Живое превью
Absolute Center Box
Использование
Скопируйте и вставьте этот код на вашу страницу Astro:
astro
---
import { AbsoluteCenterBox } from 'astro-component-kit';
---
<CenterFixedBox>Content</CenterFixedBox> ---
import { AbsoluteCenterBox } from 'astro-component-kit';
---
<CenterFixedBox>Content</CenterFixedBox> Ручная установка
Если вы не используете пакет npm, создайте файл и вставьте следующий код: src/components/lib/AbsoluteCenterBox.astro:
astro
---
/**
* CenterFixedBox — Absolute center box helper component.
*/
interface Props {
className?: string;
}
const { className = '' } = Astro.props;
---
<div class={`abs-center-container ${className}`}>
<div class="abs-center">
<slot>
<div class="abs-card">
<h4>Centered Content</h4>
<p>Centered cleanly in viewport or parent container.</p>
</div>
</slot>
</div>
</div>
<style>
.abs-center-container {
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 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: max-content;
}
.abs-card {
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 h4 {
margin: 0 0 0.25rem;
color: #fff;
}
.abs-card p {
margin: 0;
font-size: 0.85rem;
color: #94a3b8;
}
</style> ---
/**
* CenterFixedBox — Absolute center box helper component.
*/
interface Props {
className?: string;
}
const { className = '' } = Astro.props;
---
<div class={`abs-center-container ${className}`}>
<div class="abs-center">
<slot>
<div class="abs-card">
<h4>Centered Content</h4>
<p>Centered cleanly in viewport or parent container.</p>
</div>
</slot>
</div>
</div>
<style>
.abs-center-container {
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 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: max-content;
}
.abs-card {
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 h4 {
margin: 0 0 0.25rem;
color: #fff;
}
.abs-card p {
margin: 0;
font-size: 0.85rem;
color: #94a3b8;
}
</style>
Краткая информация
- Категория
- Макеты и Сетки
- Имя файла
AbsoluteCenterBox.astro- Зависимости
- Нет — чистый Astro + CSS
- Теги
- layoututilityabsolute