Animacje i przejścia CSS

Proste i złożone efekty interaktywne · INF.03

CSS Transition — Przejścia

.box { background: #0a66c2; width: 110px; height: 70px; transition: width 1s, background 1s; } .box:hover { width: 200px; background: #e54f2b; }

CSS Animation — Złożone animacje

@keyframes puls { 0% { transform: scale(1);} 50% { transform: scale(1.1);} 100% { transform: scale(1);} } .pulse { background: #e54f2b; color: #fff; padding: 14px 21px; border-radius: 11px; animation: puls 1.4s infinite; }

Połączone efekty — animacja z przejściem

@keyframes przesun { 0% { transform: translateX(0);} 50% { transform: translateX(120px);} 100% { transform: translateX(0);} } .move { background: #0a66c2; width: 110px; height:70px; animation: przesun 2s infinite alternate; transition: background 0.6s; } .move:hover { background: #e54f2b; }

Ćwiczenie: Animowane efekty CSS

Zadanie: Zrób przycisk, który pulsuje oraz blok, który po najechaniu płynnie zmienia kolor i rozmiar.
@keyframes btnpuls { 0% { transform: scale(1);} 50% { transform: scale(1.08);} 100% { transform: scale(1);} } .pulsujacy { background: #e54f2b; color: #fff; padding: 13px 20px; border-radius: 10px; animation: btnpuls 1.2s infinite; } .animblok { background: #3795e0; transition: width 2s, background 1s; width: 120px; height:70px; } .animblok:hover { width: 190px; background: #efd961; }

Checklist Animacje CSS