<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tableau Sticky - 3 Colonnes Fixes</title> <style> /* ✅ Conteneur principal avec scroll */ .table-wrapper { width: 100%; max-height: 400px; overflow: auto; border: 1px solid #ccc; scroll-snap-type: both mandatory; position: relative; } table { border-collapse: collapse; width: max-content; } th, td { padding: 10px; text-align: center; height: 40px; border: 1px solid #ccc; white-space: nowrap; min-width: 120px; } /* ✅ Fixation des cellules d'en-tête */ th { background-color: #f2f2f2; position: sticky; top: 0; z-index: 30; border-bottom: 2px solid #aaa; } /* ✅ Première colonne sticky */ th:first-child, td:first-child { position: sticky; left: 0; background-color: white; z-index: 20; min-width: 120px; border-right: 2px solid #ccc; } /* ✅ Deuxième colonne sticky */ th:nth-child(2), td:nth-child(2) { position: sticky; left: 120px; background-color: white; z-index: 21; min-width: 120px; border-right: 2px solid #ccc; } /* ✅ Troisième colonne sticky */ th:nth-child(3), td:nth-child(3) { position: sticky; left: 240px; background-color: white; z-index: 22; min-width: 120px; border-right: 2px solid #ccc; } /* ✅ Fixation des trois premières cellules de l'en-tête */ tr:first-child th:first-child { z-index: 40; } tr:first-child th:nth-child(2) { z-index: 41; } tr:first-child th:nth-child(3) { z-index: 42; } /* ✅ Ajout d'une pseudo-bordure pour éviter les coupures */ td:first-child::after, th:first-child::after, td:nth-child(2)::after, th:nth-child(2)::after, td:nth-child(3)::after, th:nth-child(3)::after { content: ""; position: absolute; right: 0; top: 0; width: 2px; height: 100%; background-color: #ccc; z-index: 45; } /* ✅ Alternance des couleurs pour lisibilité */ tbody tr:nth-child(odd) { background-color: #f9f9f9; } /* ✅ Largeur fixe des autres colonnes pour éviter le décalage */ th:nth-child(n+4), td:nth-child(n+4) { min-width: 150px; } </style> </head> <body> <div class="table-wrapper"> <table> <thead> <tr> <th></th> <!-- Coin haut gauche --> <th>plouf</th> <th>cretin</th> <!-- Nouvelle colonne ajoutée --> <?php for ($i = 1; $i <= 50; $i++): ?> <th>Col <?php echo $i; ?></th> <?php endfor; ?> </tr> </thead> <tbody> <?php for ($i = 1; $i <= 50; $i++): ?> <tr> <td>Row <?php echo $i; ?></td> <td>Data <?php echo $i . "-2"; ?></td> <td>cretin <?php echo $i; ?></td> <!-- Nouvelle cellule ajoutée --> <?php for ($j = 1; $j <= 50; $j++): ?> <td>Data <?php echo $i . "-" . $j; ?></td> <?php endfor; ?> </tr> <?php endfor; ?> </tbody> </table> </div> </body> </html>