Zoeken...  ⌘K GitHub

ImageBackground image

Sectie met achtergrondafbeelding en donker overlay.

/image-background
src/components/image/ImageBackground.astro
---
interface Props {
  src?: string;
  alt?: string;
  overlayOpacity?: number;
  minHeight?: string;
}

const {
  src = '',
  alt = 'Achtergrondafbeelding',
  overlayOpacity = 0.5,
  minHeight = '400px',
} = Astro.props;
---

<section class="ibg" style={`--ibg-opacity: ${overlayOpacity}; --ibg-min-height: ${minHeight}`}>
  {src ? (
    <img class="ibg__img" src={src} alt={alt} />
  ) : (
    <div class="ibg__placeholder" aria-label={alt}></div>
  )}
  <div class="ibg__overlay"></div>
  <div class="ibg__content">
    <slot>
      <h2 class="ibg__default-title">Jouw boodschap hier</h2>
      <p class="ibg__default-sub">Voeg inhoud toe via de slot.</p>
    </slot>
  </div>
</section>

<style>
  :root {
    --color-accent: #6366f1;
    --color-primary: #0a0a0a;
  }
  .ibg {
    position: relative;
    min-height: var(--ibg-min-height, 400px);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .ibg__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .ibg__placeholder {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #1a1a3a 0%, #2a2a5a 100%);
  }
  .ibg__overlay {
    position: absolute;
    inset: 0;
    background: rgba(10,10,10, var(--ibg-opacity, 0.5));
  }
  .ibg__content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 3rem 2rem;
    max-width: 800px;
  }
  .ibg__default-title {
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    margin: 0 0 1rem;
  }
  .ibg__default-sub {
    font-size: 1rem;
    color: rgba(255,255,255,0.8);
    margin: 0;
  }
</style>

Props

Prop Type Default Beschrijving
src string Afbeelding URL
alt string Alt-tekst
overlayOpacity number Transparantie van de overlay (0–1)
minHeight string Minimale hoogte van de sectie

* = verplicht