Przejdź do treści głównej
← 🎨 CSS as a design system·Moduł B7 · Lekcja 5
ZadanieBuild a hero entrance. @keyframes appear { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }. .hero { padding: 40px; text-align: center; }. .hero h1 animation 0.5s appear ease-out both. .hero p animation 0.5s appear ease-out 0.15s both. .hero .cta animation 0.5s appear ease-out 0.30s both, padding 10px 20px, background #3B82F6, color white, border-radius 8px, border none.

Animacje wejścia na stronę: zanikanie + przesuwanie

75 XP6 min
Teoria

The "appear smoothly on page load" pattern

@keyframes appear {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero h1 { animation: appear 0.6s ease-out forwards; }
.hero p  { animation: appear 0.6s ease-out 0.15s forwards; }   /* 150ms delay */
.hero .cta { animation: appear 0.6s ease-out 0.30s forwards; } /* 300ms delay */

Stagger the delays

Children of the hero each get a slightly LATER animation-delay. The cascade creates a "drift" effect — your eye follows from h1 → p → CTA.

50-200ms between each is the sweet spot. Less feels simultaneous; more feels disconnected.

Backwards fill-mode

.hero h1 { animation: appear 0.6s ease-out backwards; }

Without backwards, the element FLASHES into the "to" state for a frame before the animation runs (because the from state hasn't applied yet). backwards makes the browser apply the from state immediately, fixing the flash.

forwards keeps the FINAL state after the animation. backwards applies the INITIAL state before the animation. both does both — common combo.

reduced-motion alternative

For users who opted out, show the element instantly with NO motion but in the final visual state:

@media (prefers-reduced-motion: reduce) {
  .hero h1, .hero p, .hero .cta { animation: none; opacity: 1; }
}
🔒

Zarejestruj się, aby zacząć kodować

Teoria jest dostępna dla każdego. Edytor, podgląd na żywo i check odblokowują się z 7-dniowym darmowym okresem próbnym — wymagana karta, anuluj w dowolnym momencie.

Zarejestruj się — darmowy okres próbny →

Pierwsze 10 lekcji w każdej ścieżce jest darmowych. Karta nie jest wymagana.

← PoprzedniaNastępna lekcja →

Codziennie jedna wskazówka Python lub web — na maila

Krótko, ręcznie pisane, bez spamu. Wypisanie w jedno kliknięcie.