Bootstrap-4 Tabelle Reaktionsschnell Weg, Horizontale und Vertikale Bildlaufleiste

Ich bin mit bootstrap-Tabellen mit Eckigen 6 in einem Projekt, und ich war in der Lage zur Erstellung von vertikalen scrollen der Tabelle-Körper mit diesem code:

<table class="table table-striped table-bordered" style="margin-bottom: 0">
      <thead> <!-- Column names -->
        <tr>
          <th scope="col">#</th>
          <th scope="col">Col 1</th>
          <th scope="col">Col 2</th>
          <th scope="col">Col 3</th>
          ...
          <th scope="col">Col N</th>
        </tr>
      </thead>
      <tbody> <!-- Data -->
        <tr>
          <th scope="row">1</th>
          <td>AAAAA</td>
          <td>BBBBB</td>
          <td>CCCCC</td>
          ...
          <td>DDDDD</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>AAAAA</td>
          <td>BBBBB</td>
          <td>CCCCC</td>
          ...
          <td>DDDDD</td>
        </tr>
        ...
        <tr>
          <th scope="row">n</th>
          <td>AAAAA</td>
          <td>BBBBB</td>
          <td>CCCCC</td>
          ...
          <td>DDDDD</td>
        </tr>
      </tbody>
    </table>

Und css:

  tbody {
      display:block;
      max-height:500px;
      overflow-y:auto;
  }
  thead, tbody tr {
      display:table;
      width:100%;
      table-layout:fixed;
  }
  thead {
      width: calc( 100% - 1em )
  } 

Aber nun, wenn es gibt eine Menge von Spalten, es sieht nicht gut aus.

Bootstrap-4 Tabelle Reaktionsschnell Weg, Horizontale und Vertikale Bildlaufleiste

So, ich wollte hinzufügen, um eine horizontale Bildlaufleiste zu, so konnte ich scrollen, die Tabelle horizontal und nur in der Tabelle Körper vertikal.
Zu tun, mit der horizontalen Bildlaufleiste die ich verwendet habe .table-responsive wie diese:

<div class="table-responsive">
    <table class="table table-striped table-bordered" style="margin-bottom: 0">
    ...
    </table>
</div>

Aber es funktioniert nur ohne die vertikale Bildlaufleiste Teil in der css.

Bootstrap-4 Tabelle Reaktionsschnell Weg, Horizontale und Vertikale Bildlaufleiste

Möchte ich kombinieren diese beiden Möglichkeiten, um das scrollen der Tabelle.
Ich habe die Werte für die Breite und auf den css-Teil aus 100% statische px-Werte wie diese:

...
thead, tbody tr {
      display:table;
      width: 2000px;
      table-layout:fixed;
  }
  thead {
      width: calc( 2000px - 1em )
  } 

Und es hat funktioniert, aber ich brauche, um eine statische Breite und ich weiß nicht, wie kann ich dies dynamisch (je nach Anzahl der Spalten).

Bootstrap-4 Tabelle Reaktionsschnell Weg, Horizontale und Vertikale Bildlaufleiste

InformationsquelleAutor JCAguilera | 2018-06-05
Schreibe einen Kommentar