<!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; /* Assurer que padding et bordure sont inclus 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 */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Ombre pour améliorer l'impact visuel */
}
/* 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 */
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1); /* Ombre pour la première colonne */
}
/* 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 */
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1); /* Ombre pour améliorer l'effet visuel */
}
/* Défilement du tableau */
.table-wrapper {
overflow: auto;
max-height: 400px;
}
/* Pour ajuster la largeur du tableau sans chevauchement */
.table-wrapper table {
width: 100%;
table-layout: auto; /* Permet de gérer les largeurs des colonnes sans chevauchement */
}
</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>