DEV Community

Cover image for Como hacer un overlay con degradado de abajo hacia arriba usando css y tailwind
Joel Aviles
Joel Aviles

Posted on

3

Como hacer un overlay con degradado de abajo hacia arriba usando css y tailwind

Para este ejemplo estaré usando imágenes del api de lorem picsum y la etiqueta <picture>, para la nomenclatura clases en css usare BEM y las utilidades Tailwind

Demo en codi.link

Css

1️⃣ HTML

<picture class="overlay">
    <img class="overlay__image" src="https://picsum.photos/id/238/300/400" alt="perro">
    <h1 class="overlay__text">Css</h1>
</picture>
Enter fullscreen mode Exit fullscreen mode

2️⃣ CSS

Variables css

:root {
    --overlay-width: 150px;
    --overlay-height: 200px;
}
Enter fullscreen mode Exit fullscreen mode

Clase overlay

.overlay {
    width: var(--overlay-width);
    height: var(--overlay-height);
    position: relative;
}

.overlay::before {
    content: '';
    width: var(--overlay-width);
    height: var(--overlay-height);
    position: absolute;
    background: linear-gradient(to top, #1e293b, #ffffff00);
}
Enter fullscreen mode Exit fullscreen mode

Clase overlay__image

.overlay__image {
    width: var(--overlay-width);
    height: var(--overlay-height);
}
Enter fullscreen mode Exit fullscreen mode

Clase overlay__text

.overlay__text {
    position: absolute;
    color: #d1d5db;
    font-size: 1.5rem; /* 24px */
    line-height: 2rem; /* 32px */
    left: 0.75rem; /* 12px */
    bottom: 1rem; /* 16px */
}
Enter fullscreen mode Exit fullscreen mode

3️⃣ Resultado

Resultado de overlay con css

Tailwind

1️⃣ HTML

<picture class="w-80 h-96 relative before:w-80 before:h-96 before:absolute before:bg-gradient-to-t before:from-slate-800">
    <img class="w-80 h-96 object-cover" src="https://picsum.photos/id/237/300/400" alt="cuidad">
    <h1 class="absolute bottom-4 left-3 text-2xl text-gray-300">Tailwind</h3>
</picture>
Enter fullscreen mode Exit fullscreen mode

2️⃣ Resultado

Resultado de overlay con tailwind

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay