<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tableau avec Sticky Header et Sticky Colonne</title> <style> table { width: 100%; max-width: 1200px; max-height: 400px; border-collapse: collapse; overflow: auto; display: block; table-layout: fixed; /* Empêche les décalages lors du défilement */ } th, td { padding: 10px; text-align: center; border: 1px solid #ccc; box-sizing: border-box; /* S'assure que padding + bordure sont dans la largeur totale */ } /* Sticky Header */ th { background-color: #f2f2f2; position: sticky; top: 0; z-index: 2; /* Mettre les en-têtes de colonne au-dessus */ } /* Sticky First Column */ td:first-child { background-color: #f2f2f2; position: sticky; left: 0; z-index: 1; border-left: 2px solid #ccc; /* Bordure gauche visible */ padding-left: 12px; /* Espacement pour éviter le chevauchement */ } /* Sticky First Cell (top-left corner) */ th:first-child { position: sticky; top: 0; left: 0; z-index: 3; /* Mettre la cellule en haut à gauche au-dessus des autres */ background-color: #f2f2f2; border-top: 2px solid #ccc; /* Bordure supérieure */ border-left: 2px solid #ccc; /* Bordure gauche */ } /* Pour éviter que la bordure gauche de la première colonne ne soit masquée */ td:first-child { z-index: 1; /* Positionner correctement la cellule sticky au-dessus des autres */ } /* Défilement du tableau */ .table-wrapper { overflow: auto; max-height: 400px; } </style> </head> <body> <div class="table-wrapper"> <table> <thead> <tr> <th></th> <!-- Création des en-têtes de colonnes (50 colonnes) --> <?php for ($i = 1; $i <= 50; $i++): ?> <th>Col <?php echo $i; ?></th> <?php endfor; ?> </tr> </thead> <tbody> <!-- Création des lignes --> <?php for ($i = 1; $i <= 50; $i++): ?> <tr> <td>Row <?php echo $i; ?></td> <!-- Création des cellules de données --> <?php for ($j = 1; $j <= 50; $j++): ?> <td>Data <?php echo $i . "-" . $j; ?></td> <?php endfor; ?> </tr> <?php endfor; ?> </tbody> </table> </div> </body> </html>