Zoeken...  ⌘K GitHub

ImageOverlay image

Afbeelding met gradient overlay en tekst linksonder. Ideaal voor case study kaarten.

/image-overlay
src/components/image/ImageOverlay.astro
---
interface Props {
  src?: string;
  alt?: string;
  label?: string;
  title: string;
  ratio?: string;
}

const {
  src,
  alt = 'Afbeelding met overlay',
  label,
  title,
  ratio = '16/9',
} = Astro.props;
---

<section class="bl-section iov-section">
  <div class="bl-inner">
    <div class="iov" style={`--iov-ratio: ${ratio}`}>
      {src
        ? <img data-allow-img class="iov__img" src={src} alt={alt} loading="lazy" decoding="async" />
        : <div class="iov__placeholder" aria-label={alt}></div>
      }
      <div class="iov__overlay">
        {label && <span class="iov__label">{label}</span>}
        <p class="iov__title">{title}</p>
      </div>
    </div>
  </div>
</section>

<style>
  .iov {
    position: relative;
    aspect-ratio: var(--iov-ratio, 16/9);
    overflow: hidden;
    border-radius: 12px;
  }
  .iov__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
  }
  .iov:hover .iov__img {
    transform: scale(1.05);
  }
  .iov__placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2a2a4a, #1a1a3a);
  }
  .iov__overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(10, 10, 10, 0.75) 0%, transparent 60%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 1.5rem;
  }
  .iov__label {
    display: inline-block;
    background: var(--color-accent, #6366f1);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    align-self: flex-start;
  }
  .iov__title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.3;
  }
</style>

Props

Prop Type Default Beschrijving
src string - URL van de afbeelding
alt string "Afbeelding met overlay" Alt-tekst
label string - Klein accentlabel linksonder
title * string - Kop over de overlay
ratio string "16/9" Beeldverhouding (CSS aspect-ratio)

* = verplicht