Bootstrap Responsive Tables Break Vertically

bootstrap responsive table example
responsive table columns to rows
bootstrap table column width responsive
bootstrap 4 table column width
bootstrap table width
responsive table collapse rows
bootstrap 4 table-responsive not working
bootstrap table border color

I have the following html with a responsive table. When the page is accessed via mobile, the user has to scroll horizontally to view the entire content, is there a bootstrap way to break the columns vertically so a mobile user does not have to scroll horizontally ?

<!DOCTYPE html> <html> <head>   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body>

<div class="container">   <h2>Table</h2>   <p>The .table-responsive class creates a responsive table which will scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, there is no difference:</p>                                <div class="table-responsive">             <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
        <th>City</th>
        <th>Country</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>Anna</td>
        <td>Pitt</td>
        <td>35</td>
        <td>New York</td>
        <td>USA</td>
      </tr>
    </tbody>   </table>   </div> </div>

</body> </html>

The last example here (No More Tables) shows the desired behavior perfectly https://elvery.net/demo/responsive-tables/ though it is not done with bootstrap.

If anyone can shed light on how to achieve this with bootstrap, ill appreciate.

<!DOCTYPE html> <html> <head>   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body>

<style>
.table-responsive{
    width: 100%;
    margin-bottom: 15px;
    overflow-y: hidden;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    border: 1px solid #ddd;
}    
</style>

<div class="container">   <h2>Table</h2>   <p>The .table-responsive class creates a responsive table which will scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, there is no difference:</p>    <div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
        <th>City</th>
        <th>Country</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1</td>
        <td>Anna</td>
        <td>Pitt</td>
        <td>35</td>
        <td>New York</td>
        <td>USA</td>
      </tr>
    </tbody>   </table>   </div> </div>

</body> </html>

Tables · Bootstrap, table { border-collapse: collapse; width: 100%; } /* Stack rows vertically on small screens */ @media (max-width: first-break-point) { /* Hide column labels */ thead​  Or, pick a maximum breakpoint with which to have a responsive table up to by using one of .table-responsive{-sm|-md|-lg|-xl}. Vertical clipping/truncation. Responsive tables make use of overflow-y: hidden, which clips off any content that goes beyond the bottom or top edges of the table. In particular, this can clip off dropdown menus and other third-party widgets.

An alternative solution is to use Bootstrap.

HTML:

<div class="col-md-1 " style="padding-top:10%">
   <div class="row">
      <div class="col-md-2 offset-lg-1 col-sm-12 text-center feature-comparison-table-header-cell bold">
         Compare Editions
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-header-cell bold">
         Lite
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-header-cell bold">
         Standard
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-header-cell bold">
         Premium
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-header-cell bold">
         Professional
      </div>
   </div>
   <div class="row">
      <div class="col-md-2 offset-lg-1 col-sm-12 text-center feature-comparison-table-header-cell">
         Monthly Flat Rate
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-cell">
         <p>Free</p>
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-cell">
         <p>
            $40/Month
         </p>
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-cell">
         <p>
            $50/Month 
         </p>
      </div>
      <div class="col-md-2 col-sm-12 text-center feature-comparison-table-cell">
         <p>
            $60/Month
         </p>
      </div>
   </div>
</div>

The key is then just stylizing it to look like a table

#pricing-detailed-section .feature-comparison-table-header-cell {
padding: 15px;
border: 1px solid #DFE1E5;
font-size: 1rem;
padding-top: 40px;
height:100px;
}

#pricing-detailed-section .bold {

    font-weight:600;
}
#pricing-detailed-section .feature-comparison-table-cell {

    height: 100px;
    border: 1px solid 
    #DFE1E5;
    background-color:#FFF;
    display: table;
}

#pricing-detailed-section .feature-comparison-table-cell p {
    display: table-cell; 
  vertical-align: middle; 
  text-align: center; 
}

When you switch to mobile, it'll fit everything vertically. Note the code for the paragraph section solves multi-line fields not being centered.

Getting Responsive Tables to Behave, Requires different markup for vertical and horizontal tables. Will break any JS initialisation of table content. Requires lots of JS event listeners and DOM  Or, pick a maximum breakpoint with which to have a responsive table up to by using .table-responsive{-sm|-md|-lg|-xl}. Vertical clipping/truncation Responsive tables make use of overflow-y: hidden , which clips off any content that goes beyond the bottom or top edges of the table.

Use this way

@media screen and (max-width: 640px) {
  table#customDataTable caption {
    background-image: none;
  }
  table#customDataTable thead {
    display: none;
  }
  table#customDataTable tbody td {
    display: block;
    padding: .6rem;
  }
  table#customDataTable tbody tr td:first-child {
    background: #666;
    color: #fff;
  }
  table#customDataTable tbody tr td:first-child a {
    color: #fff;
  }
  table#customDataTable tbody tr td:first-child:before {
    color: rgb(225, 181, 71);
  }
  table#customDataTable tbody td:before {
    content: attr(data-th);
    font-weight: bold;
    display: inline-block;
    width: 10rem;
  }
  table#customDataTable tr th:last-child,
  table#customDataTable tr td:last-child {
    max-width: 100% !important;
    min-width: 100px !important;
    width: 100% !important;
  }
}



<table class="table" id="customDataTable">
  <thead>
    <tr>
      <th>#</th>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Age</th>
      <th>City</th>
      <th>Country</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td data-th="#">1</td>
      <td data-th="Firstname">Anna</td>
      <td data-th="Lastname">Pitt</td>
      <td data-th="Age">35</td>
      <td data-th="City">New York</td>
      <td data-th="Country">USA</td>
    </tr>
    <tr>
      <td data-th="#">1</td>
      <td data-th="Firstname">Anna</td>
      <td data-th="Lastname">Pitt</td>
      <td data-th="Age">35</td>
      <td data-th="City">New York</td>
      <td data-th="Country">USA</td>
    </tr>
    <tr>
      <td data-th="#">1</td>
      <td data-th="Firstname">Anna</td>
      <td data-th="Lastname">Pitt</td>
      <td data-th="Age">35</td>
      <td data-th="City">New York</td>
      <td data-th="Country">USA</td>
    </tr>
    <tr>
      <td data-th="#">1</td>
      <td data-th="Firstname">Anna</td>
      <td data-th="Lastname">Pitt</td>
      <td data-th="Age">35</td>
      <td data-th="City">New York</td>
      <td data-th="Country">USA</td>
    </tr>
    <tr>
      <td data-th="#">1</td>
      <td data-th="Firstname">Anna</td>
      <td data-th="Lastname">Pitt</td>
      <td data-th="Age">35</td>
      <td data-th="City">New York</td>
      <td data-th="Country">USA</td>
    </tr>
  </tbody>
</table>

https://jsfiddle.net/lalji1051/ztrjqvL8/

Accessible, Simple, Responsive Tables, Responsive tables allow tables to be scrolled horizontally with ease. with the .​table-responsive class because your table will be broken on small screens. Hi,My goal is to have a table with 100s of rows to show only some of them and the rest to be scrollable to. Basically fix the height of the table to available space in parent. Would be nice to have a header stick to the top - but not necessary.I've seen some answers on stackoverflow on how to do something like that wit

Bootstrap table responsive, Bootstrap table scroll functionality works vertically (y axis) and horizontally (x axis​). More scroll options for static tables can be found in the Table Responsive  Is it possible to display two tables, side-by-side, in Bootstrap 3? Each tried making each one col-md-6 and, although it shrinks the width, they don't wrap next to each other (instead one is on to

Bootstrap table scroll, To create a responsive table with Bootstrap, you have to wrap the table you can see the contents of your tables by scrolling horizontally. Bootstrap does not document the media queries very well. Those variables of @screen-sm, @screen-md, @screen-lg are actually referring to LESS variables and not simple CSS. When you customize Bootstrap you can change the media query breakpoints and when it compiles the @screen-xx variables are changed to whatever pixel width you defined as

Responsive Data Tables: A Comprehensive List of Solutions , Basic BS4 Typography BS4 Colors BS4 Tables BS4 Images BS4 Jumbotron BS4 Alerts BS4 Buttons Bootstrap 4 Grid Example: Stacked-to-horizontal meaning it will result in a 50%/50% split on all screens, except for extra small screens, which it The size classes determines when the columns should be responsive:. Table scroll — horizontal and vertical Bootstrap table scroll. For the tables with at huge amount of data you can use scroll functionality, as an alternative for pagination. Scrolling functionality works vertically (y-axis) and horizontally (x-axis).

Comments