<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tableau Sticky</title>
<style>
.table-wrapper {
width: 100%;
max-height: 400px;
overflow: auto;
border: 1px solid #ccc;
}
table {
border-collapse: collapse;
min-width: 1200px; /* Largeur minimale pour forcer le scroll horizontal */
}
th, td {
padding: 10px;
text-align: center;
border: 1px solid #ccc;
white-space: nowrap;
}
/* Sticky Header */
th {
background-color: #f2f2f2;
position: sticky;
top: 0;
z-index: 2;
}
/* Sticky First Column */
th:first-child, td:first-child {
position: sticky;
left: 0;
background-color: #fafafa;
min-width: 100px; /* Largeur suffisante pour éviter les chevauchements */
max-width: 100px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2); /* Simule une bordure visible */
z-index: 3;
}
/* Sticky Corner Cell */
th:first-child {
z-index: 4; /* Pour que l'en-tête reste au-dessus */
}
/* Alternance des couleurs */
tbody tr:nth-child(odd) {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th></th>
<?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>
<?php for ($j = 1; $j <= 50; $j++): ?>
<td>Data <?php echo $i . "-" . $j; ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
</body>
</html>