🎨 Guida Completa CSS

Impara il CSS con tantissimi esempi pratici e interattivi!

Concetti base CSS:

CSS: Cascading Style Sheets – rende belli i siti web
Selettori: Come “selezionare” gli elementi da stilizzare
Proprietà: Cosa cambiare (colore, dimensione, posizione…)
Valori: Come cambiarlo (rosso, 20px, center…)
Box Model: Ogni elemento è una scatola con margini e padding
Responsive: Il sito si adatta a tutti i dispositivi

1. 📖 Introduzione al CSS

▶ Cos’è il CSS?

CSS (Cascading Style Sheets) è il linguaggio che definisce l’aspetto visivo delle pagine web. Mentre HTML crea la struttura, CSS la rende bella e funzionale.

1

I tre modi per inserire CSS:

2

🔹 CSS Inline (sconsigliato)

HTML
<!-- CSS direttamente nell'elemento -->
<p style="color: blue; font-size: 20px; font-weight: bold;">
    Questo testo è blu, grande e grassetto
</p>

3

🔹 CSS Interno

HTML
<head>
    <style>
        p {
            color: blue;
            font-size: 20px;
            font-weight: bold;
        }
    </style>
</head>

4

🔹 CSS Esterno (CONSIGLIATO! ⭐)

HTML + CSS
<!-- Nel file HTML -->
<head>
    <link rel="stylesheet" href="style.css">
</head>

/* Nel file style.css */
p {
    color: blue;
    font-size: 20px;
    font-weight: bold;
}

2. 🎯 Selettori CSS – Dettagliati

▶ Selettore Universale (*)

CSS
/* Seleziona TUTTI gli elementi della pagina */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

▶ Selettore di Elemento

CSS
/* Seleziona tutti i paragrafi */
p {
    color: #333;
    line-height: 1.6;
}

/* Seleziona tutti i titoli h1 */
h1 {
    font-size: 36px;
    color: #667eea;
}

/* Seleziona tutti i link */
a {
    text-decoration: none;
    color: #667eea;
}

▶ Selettore di Classe (.)

CSS
/* HTML: <div class="box">...</div> */
.box {
    width: 300px;
    padding: 20px;
    background: #f0f0f0;
}

/* HTML: <button class="btn-primary">Clicca</button> */
.btn-primary {
    background: #667eea;
    color: white;
    padding: 10px 20px;
}

/* Più classi: <div class="card shadow">...</div> */
.card {
    border-radius: 8px;
}
.shadow {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

▶ Selettore ID (#)

CSS
/* HTML: <div id="header">...</div> */
/* ATTENZIONE: L'ID è unico, usalo solo una volta per pagina! */
#header {
    background: #2d2d2d;
    color: white;
    height: 80px;
}

#footer {
    text-align: center;
    padding: 30px;
}

▶ Selettori Combinati

CSS
/* Selettore Discendente (spazio) - tutti i p dentro div */
div p {
    color: blue;
}

/* Selettore Figlio Diretto (>) - solo i p figli diretti di div */
div > p {
    color: red;
}

/* Selettore Fratello Adiacente (+) - p subito dopo div */
div + p {
    margin-top: 20px;
}

/* Selettore Fratelli Generali (~) - tutti i p dopo div */
div ~ p {
    color: green;
}

/* Selettore Multiplo (,) - stessa regola per più elementi */
h1, h2, h3 {
    font-family: Arial, sans-serif;
    color: #2d2d2d;
}

▶ Pseudo-classi – MOLTO UTILI! ⭐

CSS
/* :hover - quando passi il mouse sopra */
button:hover {
    background: #764ba2;
    transform: scale(1.05);
}

/* :active - quando clicchi */
button:active {
    transform: scale(0.95);
}

/* :focus - quando l'elemento è selezionato (input, link) */
input:focus {
    border-color: #667eea;
    outline: none;
}

/* :first-child - primo figlio */
li:first-child {
    font-weight: bold;
}

/* :last-child - ultimo figlio */
li:last-child {
    border-bottom: none;
}

/* :nth-child(n) - n-esimo figlio */
tr:nth-child(even) {
    background: #f0f0f0; /* Righe pari */
}
tr:nth-child(odd) {
    background: white; /* Righe dispari */
}

Esempio Interattivo – Link con Pseudo-classi

<!– HTML –>
<div class=”link-demo”>
<a href=”#”>Passa il mouse qui</a>
<a href=”#”>Clicca questo link</a>
<a href=”#”>Link già visitato</a>
</div>

<!– CSS –>
.link-demo {
display: flex;
gap: 20px;
flex-wrap: wrap;
}

.link-demo a {
padding: 10px 20px;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 5px;
transition: all 0.3s ease;
}

.link-demo a:hover {
background: #764ba2;
transform: translateY(-2px);
}

.link-demo a:active {
transform: translateY(0);
}

3. 🌈 Colori e Sfondi

▶ Formati di Colore

CSS
/* 1. Nomi Colori (140 colori predefiniti) */
.box1 { color: red; }
.box2 { color: dodgerblue; }
.box3 { color: coral; }

/* 2. Esadecimale (più usato) */
.box4 { color: #FF0000; } /* Rosso */
.box5 { color: #00FF00; } /* Verde */
.box6 { color: #0000FF; } /* Blu */
.box7 { color: #F00; } /* Rosso (formato corto) */

/* 3. RGB - Red Green Blue (0-255) */
.box8 { color: rgb(255, 0, 0); } /* Rosso */
.box9 { color: rgb(102, 126, 234); } /* Viola/Blu */

/* 4. RGBA - RGB + Alpha (trasparenza 0-1) */
.box10 { background: rgba(255, 0, 0, 0.5); } /* Rosso 50% trasparente */
.box11 { background: rgba(0, 0, 0, 0.8); } /* Nero 80% opaco */

/* 5. HSL - Hue Saturation Lightness */
.box12 { color: hsl(0, 100%, 50%); } /* Rosso */
.box13 { color: hsl(240, 100%, 50%); } /* Blu */

/* 6. HSLA - HSL + Alpha */
.box14 { background: hsla(120, 100%, 50%, 0.3); } /* Verde trasparente */

Palette di Colori Esempi
#FF6B6B
#4ECDC4
#45B7D1
#667eea
#764ba2

<!– HTML –>
<div class=”color-palette”>
<div class=”color-box” style=”background: #FF6B6B;”>#FF6B6B</div>
<div class=”color-box” style=”background: #4ECDC4;”>#4ECDC4</div>
<div class=”color-box” style=”background: #45B7D1;”>#45B7D1</div>
<div class=”color-box” style=”background: #667eea;”>#667eea</div>
<div class=”color-box” style=”background: #764ba2;”>#764ba2</div>
</div>

<!– CSS –>
.color-palette {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin: 15px 0;
}

.color-box {
width: 100px;
height: 100px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

▶ Gradienti (Gradients) – SUPER FIGHI! 🔥

CSS
/* Gradiente Lineare */
.gradient-1 {
    background: linear-gradient(to right, #667eea, #764ba2);
}

/* Gradiente con angolo */
.gradient-2 {
    background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
}

/* Gradiente con più colori */
.gradient-3 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

/* Gradiente Radiale (circolare) */
.gradient-4 {
    background: radial-gradient(circle, #667eea, #764ba2);
}

Esempi di Gradienti
Gradiente →
45° Angolo
Radiale

<!– HTML –>
<div class=”demo-grid”>
<div class=”gradient-1″>Gradiente →</div>
<div class=”gradient-2″>45° Angolo</div>
<div class=”gradient-3″>Radiale</div>
</div>

<!– CSS –>
.demo-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
margin: 15px 0;
}

.gradient-1 {
background: linear-gradient(to right, #667eea, #764ba2);
color: white;
padding: 40px;
border-radius: 8px;
text-align: center;
}

.gradient-2 {
background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
color: white;
padding: 40px;
border-radius: 8px;
text-align: center;
}

.gradient-3 {
background: radial-gradient(circle, #667eea, #764ba2);
color: white;
padding: 40px;
border-radius: 8px;
text-align: center;
}

4. ✏️ Formattazione del Testo

▶ Font e Dimensioni

CSS
/* Font Family (tipo di carattere) */
.testo1 {
    font-family: Arial, Helvetica, sans-serif; /* Lista fallback */
}

.testo2 {
    font-family: 'Times New Roman', Times, serif;
}

.testo3 {
    font-family: 'Courier New', Courier, monospace;
}

/* Font da Google Fonts (nel head HTML) */
/* <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet"> */
.testo4 {
    font-family: 'Roboto', sans-serif;
}

/* Dimensioni Font */
.size-px { font-size: 16px; } /* Pixel (fisso) */
.size-em { font-size: 1.5em; } /* Relativo al parent */
.size-rem { font-size: 1.5rem; } /* Relativo al root */
.size-percent { font-size: 120%; } /* Percentuale */

/* Peso Font (grassetto) */
.peso-1 { font-weight: normal; } /* 400 */
.peso-2 { font-weight: bold; } /* 700 */
.peso-3 { font-weight: 100; } /* Ultra sottile */
.peso-4 { font-weight: 900; } /* Ultra grassetto */

▶ Stile e Decorazione

CSS
/* Stile Font */
.italic { font-style: italic; } /* Corsivo */
.oblique { font-style: oblique; } /* Obliquo */

/* Decorazione Testo */
.underline { text-decoration: underline; } /* Sottolineato */
.line-through { text-decoration: line-through; } /* Barrato */
.overline { text-decoration: overline; } /* Linea sopra */
.no-decoration { text-decoration: none; } /* Nessuna (per link) */

/* Trasformazione Testo */
.uppercase { text-transform: uppercase; } /* MAIUSCOLO */
.lowercase { text-transform: lowercase; } /* minuscolo */
.capitalize { text-transform: capitalize; } /* Prima Lettera Maiuscola */

Esempi di Formattazione Testo

Testo grande e grassetto

Testo corsivo colorato

Testo sottolineato

questo diventa maiuscolo

ogni parola ha la maiuscola

<!– HTML –>
<p style=”font-size: 24px; font-weight: bold;”>Testo grande e grassetto</p>
<p style=”font-style: italic; color: #667eea;”>Testo corsivo colorato</p>
<p style=”text-decoration: underline;”>Testo sottolineato</p>
<p style=”text-transform: uppercase;”>questo diventa maiuscolo</p>
<p style=”text-transform: capitalize;”>ogni parola ha la maiuscola</p>

<!– CSS (inline) –>
style=”font-size: 24px; font-weight: bold;”
style=”font-style: italic; color: #667eea;”
style=”text-decoration: underline;”
style=”text-transform: uppercase;”
style=”text-transform: capitalize;”

▶ Allineamento e Spaziatura

CSS
/* Allineamento Orizzontale */
.align-left { text-align: left; } /* A sinistra */
.align-center { text-align: center; } /* Centrato */
.align-right { text-align: right; } /* A destra */
.align-justify { text-align: justify; } /* Giustificato */

/* Interlinea (spazio tra righe) */
.line-height-1 { line-height: 1; } /* Compatto */
.line-height-2 { line-height: 1.6; } /* Standard leggibile */
.line-height-3 { line-height: 2; } /* Doppia spaziatura */

/* Spaziatura Lettere */
.letter-spacing-1 { letter-spacing: 2px; } /* Spazio tra lettere */
.letter-spacing-2 { letter-spacing: -1px; } /* Lettere più vicine */

/* Spaziatura Parole */
.word-spacing { word-spacing: 10px; } /* Spazio tra parole */

/* Indentazione prima riga */
.text-indent { text-indent: 50px; } /* Rientra prima riga */

▶ Effetti Testo Avanzati

CSS
/* Ombra Testo */
.text-shadow-1 {
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    /* offset-x offset-y blur colore */
}

.text-shadow-2 {
    text-shadow: 0 0 10px #667eea, 0 0 20px #764ba2;
    /* Effetto glow (bagliore) */
}

/* Testo con Gradiente (avanzato) */
.text-gradient {
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 48px;
    font-weight: bold;
}

/* Testo con Bordo (stroke) */
.text-stroke {
    -webkit-text-stroke: 2px #667eea;
    color: transparent;
    font-size: 48px;
    font-weight: bold;
}

Effetti Testo Speciali

Testo con Ombra

Testo con Gradiente!

TESTO OUTLINE

<!– HTML –>
<p class=”text-shadow”>Testo con Ombra</p>
<p class=”text-gradient”>Testo con Gradiente!</p>
<div style=”text-align: center; margin: 20px 0;”>
<span class=”text-outline”>TESTO OUTLINE</span>
</div>

<!– CSS –>
.text-shadow {
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
font-size: 24px;
text-align: center;
}

.text-gradient {
background: linear-gradient(45deg, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 36px;
font-weight: bold;
text-align: center;
}

.text-outline {
-webkit-text-stroke: 2px #667eea;
color: white;
font-size: 36px;
font-weight: bold;
}

5. 📦 Box Model – Fondamentale!

▶ Box Model Completo

Ogni elemento HTML è una “scatola” composta da: content (contenuto), padding (spaziatura interna), border (bordo), e margin (spaziatura esterna).

CSS
/* Box Model Completo */
.box {
    /* CONTENUTO */
    width: 300px;        /* Larghezza contenuto */
    height: 200px;       /* Altezza contenuto */
    
    /* PADDING (spazio interno) */
    padding: 20px;        /* Tutti i lati */
    /* OPPURE specifici: */
    padding-top: 10px;
    padding-right: 20px;
    padding-bottom: 10px;
    padding-left: 20px;
    /* Shorthand: padding: top right bottom left */
    padding: 10px 20px 10px 20px; /* orologio */
    padding: 10px 20px;   /* verticale orizzontale */
    
    /* BORDER (bordo) */
    border: 2px solid black; /* spessore stile colore */
    
    /* MARGIN (spazio esterno) */
    margin: 30px;         /* Tutti i lati */
    /* Stessa logica del padding per margini specifici */
}

Visualizzazione Box Model
CONTENT
(+ padding + border + margin)

Rosso chiaro = Padding (30px) |
Rosso scuro = Border (10px) |
Bianco = Margin (40px)

<!– HTML –>
<div class=”box-model-demo”>
CONTENT<br>
(+ padding + border + margin)
</div>

<!– CSS –>
.box-model-demo {
width: 200px;
height: 150px;
background: #667eea;
color: white;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
border: 10px solid rgba(255,0,0,0.7);
padding: 30px;
position: relative;
}

.box-model-demo::before {
content: ”;
position: absolute;
top: -40px;
left: -40px;
right: -40px;
bottom: -40px;
background: rgba(255,0,0,0.3);
z-index: -1;
}

▶ Tipi di Border (Bordi)

CSS
/* Stili di Bordo */
.border-solid { border: 3px solid black; }
.border-dashed { border: 3px dashed blue; }
.border-dotted { border: 3px dotted red; }
.border-double { border: 5px double green; }
.border-groove { border: 5px groove gray; }
.border-ridge { border: 5px ridge purple; }

/* Bordi Specifici */
.border-custom {
    border-top: 5px solid red;
    border-right: 3px dashed blue;
    border-bottom: 2px dotted green;
    border-left: 4px double purple;
}

/* Bordi Arrotondati (MOLTO USATI!) */
.rounded-1 { border-radius: 10px; } /* Tutti gli angoli */
.rounded-2 { border-radius: 50%; } /* Cerchio perfetto */
.rounded-3 { border-radius: 20px 0 20px 0; } /* Angoli alternati */
.rounded-4 { border-radius: 50px 50px 0 0; } /* Solo sopra arrotondato */

Esempi di Bordi
Solid
Dashed
Dotted
Double
Arrotondato
Cerchio

<!– HTML –>
<div class=”demo-grid”>
<div class=”bordo-solid”>Solid</div>
<div class=”bordo-dashed”>Dashed</div>
<div class=”bordo-dotted”>Dotted</div>
<div class=”bordo-double”>Double</div>
<div class=”bordo-arrotondato”>Arrotondato</div>
<div class=”bordo-cerchio”>Cerchio</div>
</div>

<!– CSS –>
.demo-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
margin: 15px 0;
}

.bordo-solid {
border: 3px solid black;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.bordo-dashed {
border: 3px dashed #667eea;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.bordo-dotted {
border: 3px dotted #FF6B6B;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.bordo-double {
border: 5px double #4ECDC4;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.bordo-arrotondato {
border: 2px solid #764ba2;
border-radius: 10px;
background: white;
padding: 20px;
text-align: center;
}

.bordo-cerchio {
border: 2px solid #667eea;
border-radius: 50%;
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
background: white;
}

▶ Box Shadow (Ombre)

CSS
/* Ombra Base */
.shadow-1 {
    box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
    /* offset-x offset-y blur colore */
}

/* Ombra Diffusa (soft shadow) */
.shadow-2 {
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Ombra Pronunciata */
.shadow-3 {
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Ombra Interna */
.shadow-inset {
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
}

/* Multiple Ombre */
.shadow-multiple {
    box-shadow: 
        0 2px 5px rgba(0,0,0,0.1),
        0 5px 15px rgba(0,0,0,0.2),
        0 10px 30px rgba(0,0,0,0.1);
}

/* Ombra Colorata (effetto glow) */
.shadow-glow {
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.6);
}

Esempi di Ombre
Ombra Base
Soft Shadow
Pronunciata
Inset
Glow Effect

<!– HTML –>
<div class=”demo-grid”>
<div class=”ombra-base”>Ombra Base</div>
<div class=”ombra-soft”>Soft Shadow</div>
<div class=”ombra-pronunciata”>Pronunciata</div>
<div class=”ombra-inset”>Inset</div>
<div class=”ombra-glow”>Glow Effect</div>
</div>

<!– CSS –>
.demo-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 15px;
margin: 15px 0;
}

.ombra-base {
box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.ombra-soft {
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.ombra-pronunciata {
box-shadow: 0 10px 30px rgba(0,0,0,0.4);
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}

.ombra-inset {
box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
background: white;
padding: 40px;
border-radius: 8px;
text-align: center;
}

.ombra-glow {
box-shadow: 0 0 25px rgba(102, 126, 234, 0.6);
background: white;
padding: 40px;
border-radius: 8px;
text-align: center;
}

6. 🎨 Layout Moderni – Flexbox & Grid

▶ Flexbox – Per Layout 1-Dimensionali

CSS
/* Container Flex */
.flex-container {
    display: flex;
    flex-direction: row; /* row | row-reverse | column | column-reverse */
    justify-content: center; /* allineamento orizzontale */
    align-items: center; /* allineamento verticale */
    flex-wrap: wrap; /* nowrap | wrap | wrap-reverse */
    gap: 20px; /* spazio tra gli elementi */
}

/* Elementi Flex */
.flex-item {
    flex: 1; /* grow shrink basis */
    flex-grow: 1; /* può crescere */
    flex-shrink: 1; /* può restringersi */
    flex-basis: 200px; /* dimensione base */
    align-self: flex-start; /* allineamento individuale */
}

Esempio Flexbox
1
2
3
4

<!– HTML –>
<div class=”flex-container”>
<div class=”flex-item”>1</div>
<div class=”flex-item”>2</div>
<div class=”flex-item”>3</div>
<div class=”flex-item”>4</div>
</div>

<!– CSS –>
.flex-container {
display: flex;
gap: 15px;
flex-wrap: wrap;
}

.flex-item {
flex: 1;
min-width: 100px;
background: #667eea;
color: white;
padding: 20px;
border-radius: 5px;
text-align: center;
}

▶ CSS Grid – Per Layout 2-Dimensionali

CSS
/* Container Grid */
.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; /* 3 colonne uguali */
    grid-template-rows: 100px auto 100px; /* altezze righe */
    gap: 20px; /* spazio tra celle */
    grid-template-areas: 
        "header header header"
        "sidebar content content"
        "footer footer footer";
}

/* Elementi Grid */
.grid-item {
    grid-column: 1 / 3; /* da colonna 1 a 3 */
    grid-row: 1; /* prima riga */
    grid-area: header; /* area nominata */
}

/* Grid Responsive */
.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

Esempio CSS Grid
1
2
3
4
5
6

<!– HTML –>
<div class=”grid-container”>
<div class=”grid-item”>1</div>
<div class=”grid-item”>2</div>
<div class=”grid-item”>3</div>
<div class=”grid-item”>4</div>
<div class=”grid-item”>5</div>
<div class=”grid-item”>6</div>
</div>

<!– CSS –>
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 15px;
}

.grid-item {
background: #667eea;
color: white;
padding: 20px;
border-radius: 5px;
text-align: center;
}

7. ✨ Animazioni e Transizioni

▶ Transizioni – Smooth Changes

CSS
/* Transizione Base */
.transition-base {
    transition: all 0.3s ease;
    /* property duration timing-function delay */
}

.transition-specific {
    transition-property: transform, background-color;
    transition-duration: 0.3s, 0.5s;
    transition-timing-function: ease-out;
    transition-delay: 0.1s;
}

/* Esempi di Timing Functions */
.ease { transition-timing-function: ease; }
.linear { transition-timing-function: linear; }
.ease-in { transition-timing-function: ease-in; }
.ease-out { transition-timing-function: ease-out; }
.ease-in-out { transition-timing-function: ease-in-out; }
.cubic-bezier { transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55); }

▶ Animazioni CSS – @keyframes

CSS
/* Definizione Animazione */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-30px);
    }
    60% {
        transform: translateY(-15px);
    }
}

/* Applicazione Animazione */
.animated-element {
    animation-name: slideIn;
    animation-duration: 1s;
    animation-timing-function: ease-out;
    animation-delay: 0.5s;
    animation-iteration-count: infinite; /* 1 | infinite */
    animation-direction: alternate; /* normal | reverse | alternate */
    animation-fill-mode: both; /* none | forwards | backwards | both */
    
    /* Shorthand */
    animation: slideIn 1s ease-out 0.5s infinite alternate both;
}

Esempi di Animazioni
Questo box ha un’animazione di ingresso!
Passa il mouse per ruotare! ⟳

<!– HTML –>
<div class=”animated-box”>
Questo box ha un’animazione di ingresso!
</div>
<div style=”text-align: center; margin: 30px 0;”>
<span class=”hover-rotate”>Passa il mouse per ruotare! ⟳</span>
</div>
<div style=”text-align: center;”>
<button class=”btn-example-2″>Hover Me</button>
<button class=”btn-example-3″>Click Me</button>
</div>

<!– CSS –>
.animated-box {
background: #667eea;
color: white;
padding: 30px;
border-radius: 8px;
text-align: center;
animation: slideIn 1s ease-out;
}

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

.hover-rotate {
display: inline-block;
padding: 15px 30px;
background: #667eea;
color: white;
border-radius: 5px;
transition: transform 0.5s ease;
}

.hover-rotate:hover {
transform: rotate(360deg);
}

.btn-example-2 {
background: transparent;
color: #667eea;
border: 2px solid #667eea;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.btn-example-2:hover {
background: #667eea;
color: white;
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.btn-example-3 {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
border: none;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.btn-example-3:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

8. 🚀 Esempi Pratici e Componenti

▶ Bottoni Stilizzati

Vari Tipi di Bottoni


<!– HTML –>
<button class=”btn-example-1″>Button Primary</button>
<button class=”btn-example-2″>Button Outline</button>
<button class=”btn-example-3″>Button Gradient</button>

<!– CSS –>
.btn-example-1 {
background: #667eea;
color: white;
border: none;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.btn-example-1:hover {
background: #764ba2;
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.btn-example-2 {
background: transparent;
color: #667eea;
border: 2px solid #667eea;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.btn-example-2:hover {
background: #667eea;
color: white;
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.btn-example-3 {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
border: none;
padding: 12px 25px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}

.btn-example-3:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

▶ Card Moderne

Esempi di Card

Card Semplice

Questa è una card base con ombra leggera.

Card con Hover

Passa il mouse per vedere l’effetto!

Card Gradient

Card con sfondo gradient e testo bianco.

<!– HTML –>
<div class=”card-simple”>
<h4>Card Semplice</h4>
<p>Questa è una card base con ombra leggera.</p>
</div>

<div class=”card-hover”>
<h4>Card con Hover</h4>
<p>Passa il mouse per vedere l’effetto!</p>
</div>

<div class=”card-gradient”>
<h4>Card Gradient</h4>
<p>Card con sfondo gradient e testo bianco.</p>
</div>

<!– CSS –>
.card-simple {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.card-hover {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 3px 10px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}

.card-hover:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.card-gradient {
background: linear-gradient(45deg, #667eea, #764ba2);
color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

🎉 Congratulazioni!

Hai completato la guida CSS completa con tantissimi esempi pratici.

Pratica, sperimenta e crea progetti fantastici!

Ricorda: il CSS si impara facendo. Copia questi esempi, modificali e crea le tue varianti!

Torna in alto