File "tmp002.php"
Full Path: /home/analogde/www/Design/Dev tableau/tmp002.php
File size: 5.36 KB
MIME-type: text/html
Charset: utf-8
<!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 */
.table-wrapper {
width: 100%;
max-height: 400px;
overflow: auto;
border: 1px solid #ccc;
position: relative;
}
table {
border-collapse: collapse;
width: max-content;
table-layout: fixed; /* ✅ Stabilise la hauteur des lignes */
}
th, td {
padding: 10px;
text-align: center;
height: 40px;
border: 1px solid #ccc;
white-space: nowrap;
min-width: 120px;
position: relative;
background-color: white;
box-sizing: border-box; /* ✅ Empêche la réduction de hauteur */
}
/* ✅ Fixation des cellules d'en-tête */
th {
background-color: #f2f2f2;
position: sticky;
top: 0;
z-index: 60; /* ✅ Priorité pour les en-têtes */
border-bottom: 2px solid #aaa;
}
/* ✅ Colonnes sticky */
th:first-child, td:first-child {
position: sticky;
left: 0;
z-index: 61; /* ✅ Toujours au-dessus des autres colonnes */
background-color: white;
}
th:nth-child(2), td:nth-child(2) {
position: sticky;
left: 120px;
z-index: 60;
background-color: white;
}
th:nth-child(3), td:nth-child(3) {
position: sticky;
left: 240px;
z-index: 59;
background-color: white;
}
/* ✅ Bordures droites persistantes */
th:first-child::after, td:first-child::after,
th:nth-child(2)::after, td:nth-child(2)::after,
th:nth-child(3)::after, td:nth-child(3)::after {
content: "";
position: absolute;
right: 0;
top: 0;
width: 2px;
height: 100%;
background-color: #ccc;
z-index: 62;
}
/* ✅ Alternance des couleurs */
tbody tr:nth-child(odd) {
background-color: #f9f9f9;
}
/* ✅ Largeur fixe des autres colonnes */
th:nth-child(n+4), td:nth-child(n+4) {
min-width: 150px;
}
/* ✅ Deuxième ligne d'en-tête sticky */
.second-header th, .second-header td {
background-color: #f2f2f2;
position: sticky;
top: 40px; /* ✅ Aligne sous la première ligne */
z-index: 59;
border-bottom: 2px solid #aaa;
height: 40px;
box-sizing: border-box;
}
/* ✅ Correction du positionnement des 3 premières colonnes de la deuxième ligne */
.second-header th:nth-child(1), .second-header td:nth-child(1) {
left: 0;
z-index: 61;
background-color: white;
}
.second-header th:nth-child(2), .second-header td:nth-child(2) {
left: 120px;
z-index: 60;
background-color: white;
}
.second-header th:nth-child(3), .second-header td:nth-child(3) {
left: 240px;
z-index: 59;
background-color: white;
}
/* ✅ Correction du z-index pour éviter le recouvrement */
thead tr:first-child th:first-child,
thead tr:first-child th:nth-child(2),
thead tr:first-child th:nth-child(3) {
z-index: 70; /* ✅ Max priorité pour éviter le recouvrement */
background-color: #ddd;
}
.second-header th:first-child,
.second-header th:nth-child(2),
.second-header th:nth-child(3) {
z-index: 69; /* ✅ Garder la deuxième ligne sous la première */
}
</style>
</head>
<body>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th></th> <!-- Coin haut gauche -->
<th>plouf</th>
<th>cretin</th>
<?php for ($i = 1; $i <= 50; $i++): ?>
<th>Col <?php echo $i; ?></th>
<?php endfor; ?>
</tr>
<!-- ✅ Deuxième ligne d'en-tête sticky -->
<tr class="second-header">
<th></th>
<th>Valeur 1</th>
<th>Valeur 2</th>
<?php for ($i = 1; $i <= 50; $i++): ?>
<th>Val <?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>
<?php for ($j = 1; $j <= 50; $j++): ?>
<td>Data <?php echo $i . "-" . $j; ?></td>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</tbody>
</table>
</div>
</body>
</html>