Przejdź do treści głównej
← 🎨 CSS as a design system·Moduł B7 · Lekcja 1
ZadanieBuild a button with a smooth transition on hover. .button { padding: 10px 20px; background: #3B82F6; color: white; border: none; border-radius: 8px; transition: background 0.15s ease, transform 0.15s ease; }. .button:hover { background: #2563EB; transform: translateY(-1px); }.

przejście a animacja: kiedy używać każdego z nich

75 XP6 min
Teoria

Two flavors of CSS motion

/* TRANSITION — interpolate between two states */
.button {
  background: #3B82F6;
  transition: background 0.15s ease;
}
.button:hover { background: #2563EB; }

/* ANIMATION — multi-keyframe sequence, can loop */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.heart { animation: pulse 1.5s infinite; }

When transition wins

Two states: A → B → A. Triggered by user action OR class change.

  • Hover effects (color, transform, shadow).
  • Tab switching (slide content in/out).
  • Modal open/close (opacity, transform).
  • Focus rings (outline appears smoothly).

ONE property changes, ONE direction at a time. Reverses automatically when the trigger is removed.

When animation wins

Multi-step or LOOPING motion.

  • Loading spinners (continuous rotation).
  • Page-load entrance (fade + slide).
  • Attention-pull (pulse, shake).
  • Multi-stage sequences.

@keyframes declares the timeline; animation: name duration timing iteration applies it.

Don't reach for animation when transition fits

Transition is simpler, more testable, and respects :hover / :focus natively. Use animation only when you need keyframes or looping.

🔒

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.