CSS Style de Table
Rembourrage de Table CSS
Pour ajouter un peu plus d'espace entre les bordures intérieures et le contenu d'une table, utilisez la propriété padding sur les éléments <td> et <th> :
| Prénom | Nom | Économies |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Exemple
th, td {
padding: 10px;
text-align: left;
} Séparateurs Horizontaux CSS
Pour créer des séparateurs horizontaux dans une table, ajoutez la propriété border-bottom aux éléments <th> et <td> :
| Prénom | Nom | Économies |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Exemple
th, td {
border-bottom: 1px solid #ddd;
} Table CSS Survolable
Utilisez le sélecteur CSS :hover sur <tr> pour mettre en surbrillance les lignes de la table au survol de la souris :
| Prénom | Nom | Économies |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Exemple
tr:hover {background-color: coral;} Table CSS Rayée Zebra
Pour les tables rayées, utilisez le sélecteur nth-child() et ajoutez une background-color à toutes les lignes de table paires (ou impaires) :
| Prénom | Nom | Économies |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Exemple
tr:nth-child(even) {background-color: #f2f2f2;} Couleur de Table CSS
L'exemple ci-dessous spécifie une couleur de fond et une couleur de texte pour les éléments <th> :
| Prénom | Nom | Économies |
|---|---|---|
| Peter | Griffin | $100 |
| Lois | Griffin | $150 |
| Joe | Swanson | $300 |
Exemple
th {
background-color: #04AA6D;
color: white;
}