Menu
Coddy logo textTech

Selettore fratello adiacente

Fa parte della sezione Padronanza di CSS del percorso HTML di Coddy. Lezione 4 di 43.

Il selettore di fratelli adiacenti (+) viene usato per applicare uno stile a un elemento che si trova subito dopo un elemento specifico. Entrambi devono avere lo stesso elemento genitore e «adiacenti» significa «immediatamente uno accanto all’altro».

Per esempio:

<h2>Heading</h2>
<p>This paragraph is styled</p>

Con questo CSS:

h2 + p {
  font-weight: bold;
}

Il paragrafo è formattato perché segue direttamente un elemento h2.

challenge icon

Sfida

Facile

Crea un selettore CSS che individui solo i paragrafi (<p>) che seguono direttamente un elemento <h2> che descrive una partita di basket. Imposta per questi paragrafi il colore del carattere blu e la dimensione del carattere di 18px.

Provalo tu

<html>
<head>
    <title>Adjacent Sibling Selector</title>
    <style>
        /* CSS solution goes here */
        
    </style>
</head>
<body>
    <h2>Basketball Game Overview</h2>
    <p>The basketball game was an exciting match between the **Los Angeles Lakers** and the **Golden State Warriors**, featuring intense offense and solid defense from both teams.</p>
    
    <p>During the first half, the Lakers held a slight lead, with LeBron James making key plays, while Stephen Curry of the Warriors kept the game tight with impressive three-pointers.</p>
    
    <p>This paragraph is not directly after an h2, so it should not be affected.</p>
    
    <p>In the second half, the Warriors fought back, with Klay Thompson hitting critical shots, but the Lakers secured their win with solid defense and a game-winning dunk by Anthony Davis.</p>
</body>
</html>
quiz iconMettiti alla prova

Questa lezione include un breve quiz. Inizia la lezione per rispondere e tenere traccia dei tuoi progressi.

Tutte le lezioni di Padronanza di CSS

Esercitati da solo: Playground Web