1 estrella en GitHub = 1 componente nuevo.

Dar una estrella
Estructura & Layout layoututilityabsolute

Absolute Center Box

Caja de contenido centrada exacta en el visor con dimensiones máximas controladas.

Vista Previa en Vivo

Absolute Center Box

Uso

Copia y pega este código directamente en tu página de Astro:

astro
---
import { AbsoluteCenterBox } from 'astro-component-kit';
---

<CenterFixedBox>Content</CenterFixedBox>
--- import { AbsoluteCenterBox } from 'astro-component-kit'; --- <CenterFixedBox>Content</CenterFixedBox>

Instalación Manual

Si no estás usando el paquete npm, crea un archivo nuevo y pega el siguiente código: 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>

Información Rápida

Categoría
Estructura & Layout
Nombre de archivo
AbsoluteCenterBox.astro
Dependencias
Ninguna — Astro nativo + CSS puro
Etiquetas
layoututilityabsolute