File "code035.php"

Full Path: /home/analogde/www/Dev tableau/code035.php
File size: 3.6 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 avec Scroll Snap (Firefox + Chrome)</title>
    <style>
        .table-wrapper {
            width: 100%;
            max-height: 400px;
            overflow-y: auto;
            border: 1px solid #ccc;
            scroll-snap-type: y mandatory;
        }

        /* ✅ Wrapper pour scroll horizontal */
        .table-scroll {
            overflow-x: auto;
            scroll-snap-type: x mandatory;
            display: flex;
        }

        /* ✅ Flexbox pour corriger le bug Firefox */
        table {
            border-collapse: collapse;
            min-width: 2000px;
            display: flex;
            flex-direction: column;
        }

        thead {
            flex: none;
        }

        tbody {
            flex: auto;
            display: block;
        }

        tr {
            display: flex;
            flex-wrap: nowrap;
            scroll-snap-align: start;
        }

        th, td {
            padding: 10px;
            text-align: center;
            border: 1px solid #ccc;
            white-space: nowrap;
            min-width: 120px;
            scroll-snap-align: start;
        }

        /* ✅ Sticky Header */
        th {
            background-color: #f2f2f2;
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        /* ✅ Sticky First Column */
        th:first-child, td:first-child {
            position: sticky;
            left: 0;
            background-color: #fff;
            min-width: 120px;
            max-width: 120px;
            padding-right: 10px;
            z-index: 999;
        }

        /* ✅ Bordure droite persistante */
        th:first-child::after, td:first-child::after {
            content: "";
            position: absolute;
            top: 0;
            right: 0;
            width: 2px;
            height: 100%;
            background-color: #ccc;
        }

        /* ✅ Sticky haut-gauche */
        th:first-child {
            position: sticky;
            top: 0;
            left: 0;
            z-index: 1001;
            background-color: #eee;
        }

        /* ✅ Bordure inférieure persistante */
        th:first-child::before {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background-color: #ccc;
        }

        /* ✅ Alternance des couleurs */
        tbody tr:nth-child(odd) {
            background-color: #f9f9f9;
        }

    </style>
</head>
<body>

<div class="table-wrapper">
    <div class="table-scroll">
        <table>
            <thead>
                <tr>
                    <th></th> <!-- ✅ Cellule haut-gauche sticky -->
                    <?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>
</div>

</body>
</html>