File "table_boostrap_004.php"

Full Path: /home/analogde/www/Dev tableau/table_boostrap_004.php
File size: 3.49 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 avec Défilement</title>
  <!-- Lien vers Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEJ6hu7N9R3K5wCoPY5i2hPnZjVqX7f2FMY6rnxjtb+HAjsaayjGVoF2A+Ug5" crossorigin="anonymous">
  <style>
    /* Conteneur de la table avec barre de défilement horizontale */
    .table-container {
      overflow-x: auto; /* Permet de faire défiler horizontalement */
      max-width: 100%;
    }

    table {
      width: 100%;
      border-collapse: collapse; /* Pour éviter les espaces entre les bordures */
    }

    th, td {
      text-align: center;
      padding: 15px 25px;
      border: 1px solid #dee2e6; /* Bordures visibles */
      white-space: nowrap; /* Empêche la coupe des mots */
    }

    /* Les deux premières colonnes sticky */
    th:nth-child(1), td:nth-child(1) {
      position: sticky;
      left: 0;
      background-color: #f8f9fa;
      z-index: 3; /* Plus élevé pour rester au-dessus des autres */
      border-right: 2px solid #dee2e6; /* Bordure pour séparer */
      width: 120px; /* Fixe la largeur de la première colonne */
    }

    th:nth-child(2), td:nth-child(2) {
      position: sticky;
      left: 120px; /* Position après la première colonne */
      background-color: #f8f9fa;
      z-index: 2; /* Juste en dessous de la première colonne sticky */
      border-right: 2px solid #dee2e6; /* Bordure pour séparer */
      width: 150px; /* Fixe la largeur de la deuxième colonne */
    }

    /* Pour les colonnes restantes qui défileront */
    th:nth-child(n+3), td:nth-child(n+3) {
      min-width: 150px; /* Largeur minimale pour les colonnes restantes */
      max-width: 200px; /* Empêche les colonnes de devenir trop larges */
    }

    /* Style d'en-tête */
    th {
      background-color: #007bff;
      color: white;
    }

    td {
      background-color: #f1f1f1;
    }
    
    /* Fixe les bordures des cellules et gère l'alignement lors du défilement */
    .table th, .table td {
      border-right: 1px solid #dee2e6;
    }
    .table th:first-child, .table td:first-child {
      border-left: 1px solid #dee2e6;
    }
  </style>
</head>
<body>
  <div class="container mt-5">
    <div class="table-container">
      <table class="table table-bordered">
        <thead>
          <tr>
            <th>Jour</th>
            <th>Mois</th>
            <th>Semaine</th>
            <?php
              // Générer les colonnes supplémentaires jusqu'à 200
              for ($i = 4; $i <= 200; $i++) {
                echo "<th>Colonne $i</th>";
              }
            ?>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Total</td>
            <td></td>
            <td></td>
            <?php
              // Générer les valeurs pour chaque colonne (exemple)
              for ($i = 4; $i <= 200; $i++) {
                echo "<td>Valeur $i</td>";
              }
            ?>
          </tr>
          <tr>
            <td>Jour 1</td>
            <td>Janvier</td>
            <td>1</td>
            <?php
              // Remplir les valeurs pour chaque colonne
              for ($i = 4; $i <= 200; $i++) {
                echo "<td>Valeur $i</td>";
              }
            ?>
          </tr>