Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 table - table-responsive not working

Tags:

I'm using bootstrap 3 for a website project. I'm trying to create a page with a responsive table, so that I'd have the scrollbar when the table is too big. I made a test case like so:

<div class="row">   <h4>Nuværende kurser</h4>   <div class="col-12 col-sm-12 col-lg-12">     <div class="table-responsive">       <table class="table">         <thead>           <tr>             <th>#</th>             <th>Table heading</th>             <th>Table heading</th>             <th>Table heading</th>             <th>Table heading</th>             <th>Table heading</th>             <th>Table heading</th>           </tr>         </thead>         <tbody>           <tr>             <td>1</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>           </tr>           <tr>             <td>2</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>           </tr>           <tr>             <td>3</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>             <td>Table cell</td>           </tr>         </tbody>       </table>     </div>   </div><!-- end col-12 --> </div><!-- end row --> 

Now, the problem is that it doesn't add the scrollbar, it merely expands the website to the width of the table.

See a screenshot here:

enter image description here

I've seen it working on several other websites, so something I'm doing...is wrong.

like image 591
Daniel Olsen Avatar asked Oct 15 '14 23:10

Daniel Olsen


People also ask

Why table responsive is not working in bootstrap?

Make sure you checked you have inserted enough data in table. Sometimes there is just not enough data to trigger 'table-responsive' property.

How do I make my table responsive?

Responsive tables with flexboxOrder markup exactly how a mobile or screen reader should read it, use semantic headers and content. Abandon all concept of 'row' wrappers. Set the width of each cell as a percentage based on number of columns or rows. Auto sizing column widths is not possible.

How do I make a table responsive in stackoverflow?

To make a responsive table, you can make the width of each td 100% and insert a related heading in the td on mobile browsers (that are less 768px width.)


2 Answers

Replace your table-responsive with this

<div class='table-responsive'> -> <div style="overflow-x:auto;"> 
like image 122
Savan Kachhiya Patel Avatar answered Oct 27 '22 00:10

Savan Kachhiya Patel


Make sure to set your table display block

.table {    display: block !important; } 
like image 22
Hamza AVvan Avatar answered Oct 27 '22 01:10

Hamza AVvan