:nth-child() (selettore CSS e jQuery) riguarda gli elementi HTML che -secondo quanto passato nel suo parametro- siano di numero pari (even), dispari (odd) o l’n-esimo elemento (a partire dal primo) (molto utile, ad esempio, nelle tabelle, in cui è possibile individuare una certa riga).
Sintassi
:nth-child() {
/* codice */
}
Esempi
<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
<tr><td>10</td><td>11</td><td>12</td></tr>
<tr><td>14</td><td>15</td><td>16</td></tr>
</table>
<style>
tr:nth-child(odd) {
background-color: blue;
}
tr:nth-child(even) {
background-color: red;
}
tr:nth-child(3) {
background-color: yellow;
}
</style>
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
| 10 | 11 | 12 |
| 14 | 15 | 16 |
Contenuti correlati
- CSS
- HTML
- JavaScript
- jQuery
- PHP
- SQL
- WORDPRESS
0 Comment