Styliser les Tableaux avec CSS
Transformez les tableaux HTML basiques en présentations de données visuellement attrayantes et professionnelles.
Stylisation de Base des Tableaux
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-family: Arial, sans-serif;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f8f9fa;
font-weight: 600;
color: #333;
text-transform: uppercase;
font-size: 0.9em;
letter-spacing: 0.5px;
}
tr:hover {
background-color: #f5f5f5;
}
/* Couleurs alternées des lignes */
tr:nth-child(even) {
background-color: #f9f9f9;
}
Design Moderne de Tableau
.modern-table {
width: 100%;
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
min-width: 400px;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}
.modern-table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
.modern-table th,
.modern-table td {
padding: 12px 15px;
}
.modern-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.modern-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.modern-table tbody tr:last-of-type {
border-bottom: 2px solid #009879;
}
.modern-table tbody tr:hover {
background-color: #f1f1f1;
transform: scale(1.02);
transition: all 0.3s ease;
}
Design Responsif de Tableau
.responsive-table {
width: 100%;
border-collapse: collapse;
}
@media screen and (max-width: 768px) {
.responsive-table {
border: 0;
}
.responsive-table caption {
font-size: 1.3em;
}
.responsive-table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
.responsive-table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: 10px;
}
.responsive-table td {
border: none;
border-bottom: 1px solid #eee;
display: block;
font-size: 0.8em;
text-align: right;
padding-left: 50%;
position: relative;
}
.responsive-table td:before {
content: attr(data-label);
position: absolute;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
font-weight: bold;
text-align: left;
}
}
<table class="responsive-table">
<thead>
<tr>
<th>Nom</th>
<th>Position</th>
<th>Bureau</th>
<th>Salaire</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Nom">Jean Dupont</td>
<td data-label="Position">Développeur</td>
<td data-label="Bureau">Paris</td>
<td data-label="Salaire">75 000 €</td>
</tr>
</tbody>
</table>
Tableau avec Boutons d'Action
.action-table {
width: 100%;
border-collapse: collapse;
}
.action-table th,
.action-table td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.action-buttons {
display: flex;
gap: 8px;
}
.btn {
padding: 6px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.8em;
text-decoration: none;
display: inline-block;
transition: background-color 0.3s;
}
.btn-edit {
background-color: #007bff;
color: white;
}
.btn-edit:hover {
background-color: #0056b3;
}
.btn-delete {
background-color: #dc3545;
color: white;
}
.btn-delete:hover {
background-color: #c82333;
}
<table class="action-table">
<thead>
<tr>
<th>ID</th>
<th>Nom</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>001</td>
<td>Jean Dupont</td>
<td>jean@exemple.com</td>
<td>
<div class="action-buttons">
<a href="#" class="btn btn-edit">Modifier</a>
<button class="btn btn-delete">Supprimer</button>
</div>
</td>
</tr>
</tbody>
</table>