Vai al contenuto principale
← 🎨 CSS as a design system·Modulo B5 · Lezione 9
CompitoDefine --shadow-sm and --shadow-md tokens. .card has padding 20px, background white, border-radius 12px, box-shadow var(--shadow-sm), transition 'box-shadow 0.15s'. .card:hover gets var(--shadow-md).

La scatola-ombra come tema primitivo

75 XP6 min
Teoria

Shadows for elevation — token them too

:root {
  --shadow-xs: 0 1px 2px 0 oklch(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 oklch(0 0 0 / 0.10), 0 1px 2px -1px oklch(0 0 0 / 0.10);
  --shadow-md: 0 4px 6px -1px oklch(0 0 0 / 0.10), 0 2px 4px -2px oklch(0 0 0 / 0.10);
  --shadow-lg: 0 10px 15px -3px oklch(0 0 0 / 0.10), 0 4px 6px -4px oklch(0 0 0 / 0.10);
}

The "double-shadow" technique

A single shadow looks fake. The Tailwind shadow scale (and most modern systems) layer TWO shadows: one sharp + close, one soft + far. The combination mimics real light scatter.

.card-resting { box-shadow: var(--shadow-sm); }
.card-hover   { box-shadow: var(--shadow-md); transition: box-shadow 0.15s; }

Promote a card on hover by jumping one shadow tier. Subtle "elevates toward the user" feel.

Dark mode shadow tip

On dark backgrounds, dark shadows are invisible. Use a slight WHITE rim shadow + dark drop for elevation:

@media (prefers-color-scheme: dark) {
  :root {
    --shadow-md: 0 0 0 1px oklch(1 0 0 / 0.05), 0 4px 6px oklch(0 0 0 / 0.5);
  }
}

The first shadow is a 1px ring of barely-visible white — the "edge" you'd otherwise lose in dark mode.

🔒

Iscriviti per iniziare a programmare

La teoria è aperta a tutti. Editor, anteprima e check si sbloccano con una prova gratuita di 7 giorni — carta richiesta, annullabile in qualsiasi momento.

Iscriviti — prova gratuita →

Le prime 10 lezioni di ogni percorso sono gratuite. Nessuna carta richiesta.

← PrecedenteProssima lezione →

Ricevi un consiglio Python o web al giorno — via email

Breve, scritto a mano, niente spam. Disiscriviti in un clic.