File "code052.php"

Full Path: /home/analogde/www/Dev tableau/code052.php
File size: 4.63 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;
            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;
            position: relative;
            background-color: white; /* Empêche l’effet de recouvrement */
        }

        /* ✅ Fixation des cellules d'en-tête */
        th {
            background-color: #f2f2f2;
            position: sticky;
            top: 0;
            z-index: 40; /* Plus haut que les colonnes fixes */
            border-bottom: 2px solid #aaa;
        }

        /* ✅ Première colonne sticky */
        th:first-child, td:first-child {
            position: sticky;
            left: 0;
            z-index: 30;
            min-width: 120px;
            padding-right: 12px;
            background-color: white;
        }

        /* ✅ Deuxième colonne sticky */
        th:nth-child(2), td:nth-child(2) {
            position: sticky;
            left: 120px;
            z-index: 29;
            min-width: 120px;
            padding-right: 12px;
            background-color: white;
        }

        /* ✅ Troisième colonne sticky */
        th:nth-child(3), td:nth-child(3) {
            position: sticky;
            left: 240px;
            z-index: 28;
            min-width: 120px;
            padding-right: 12px;
            background-color: white;
        }

        /* ✅ Assurer que l'en-tête de la première colonne reste bien en haut */
        th:first-child {
            position: sticky;
            top: 0;
            left: 0;
            z-index: 50; /* Priorité maximale */
            background-color: #ddd;
            border-bottom: 2px solid #aaa;
        }

        /* ✅ Assurer que l'en-tête de la deuxième colonne reste bien en haut */
        th:nth-child(2) {
            position: sticky;
            top: 0;
            left: 120px;
            z-index: 49;
            background-color: #ddd;
            border-bottom: 2px solid #aaa;
        }

        /* ✅ Assurer que l'en-tête de la troisième colonne reste bien en haut */
        th:nth-child(3) {
            position: sticky;
            top: 0;
            left: 240px;
            z-index: 48;
            background-color: #ddd;
            border-bottom: 2px solid #aaa;
        }

        /* ✅ 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: 55;
        }

        /* ✅ 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;
        }
    </style>
</head>
<body>

<div class="table-wrapper">
    <table>
        <thead>
            <tr>
                <th></th> <!-- Coin haut gauche -->
                <th>plouf</th>
                <th>cretin</th> <!-- Nouvelle colonne -->
                <?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 -->
                    <?php for ($j = 1; $j <= 50; $j++): ?>
                        <td>Data <?php echo $i . "-" . $j; ?></td>
                    <?php endfor; ?>
                </tr>
            <?php endfor; ?>
        </tbody>
    </table>
</div>

</body>
</html>