Zoeken...  ⌘K GitHub

ImageOverlay image

Afbeelding met tekstoverlay bij hover.

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

const {
  src = '',
  alt = 'Afbeelding met overlay',
  label = 'Case study',
  title = '+340% omzetgroei in 6 maanden',
  aspectRatio = '16/9',
} = Astro.props;
---

<div class="iov" style={`--iov-ratio: ${aspectRatio}`}>
  {src ? (
    <img class="iov__img" src={src} alt={alt} />
  ) : (
    <div class="iov__placeholder" aria-label={alt}></div>
  )}
  <div class="iov__overlay">
    <span class="iov__label">{label}</span>
    <p class="iov__title">{title}</p>
  </div>
</div>

<style>
  :root {
    --color-accent: #6366f1;
    --color-primary: #0a0a0a;
  }
  .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 0%, #1a1a3a 100%);
  }
  .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 Afbeelding URL
alt string Alt-tekst
label string Kleine categorie-label
title string Titel op de overlay
aspectRatio string CSS aspect-ratio

* = verplicht