Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap3 responsiveness for table is not working

<div class="table-responsive">
<table class="table">
...
</table>
</div>

This code block is not resulting in responsive table in Bootstrap. Please help me in achieving the responsive table using bootstrap. Thanks in advance

like image 590
sulthana Avatar asked Sep 03 '13 06:09

sulthana


People also ask

How do you add responsiveness to a table in HTML?

The primary method of making a responsive table is to add a class table table-responsive inside the table tag. To make a table responsive, we wrap the whole table inside a container tag like div with property overflow-x equals to auto .

Which class is used for table responsiveness in Bootstrap?

Use . table-responsive{-sm|-md|-lg|-xl} classes as needed to create responsive tables up to a particular breakpoint. From that breakpoint and up, the table will behave normally and not scroll horizontally.


4 Answers

Following Responsive table will works only <768px.

<div class="table-responsive">
    <table class="table">
    </table>
</div>

Because bootstrap 3 has following code

@media (max-width: 767px) {
    .table-responsive {
        width: 100%;
        margin-bottom: 15px;
        overflow-y: hidden;
        overflow-x: scroll;
        -ms-overflow-style: -ms-autohiding-scrollbar;
        border: 1px solid #DDD;
        -webkit-overflow-scrolling: touch;
    }
}

If you want responsive table for display >768px, then you can overwrite it in your css without media query just like this

.table-responsive {
    width: 100%;
    margin-bottom: 15px;
    overflow-y: hidden;
    overflow-x: scroll;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    border: 1px solid #DDD;
    -webkit-overflow-scrolling: touch;
}
like image 107
Fizer Khan Avatar answered Nov 22 '22 13:11

Fizer Khan


I know the documentation says so which I have asked .table-responsive doesn't work in div above the table but adding it to the table class works ... Do the following and your issue should be solved.

Not working:

<div class="table-responsive">
  <table class="table">
  ......
  </table>
</div>

Works:

<table class="table table-responsive">
......
</table>

DEMO

like image 26
Shina Avatar answered Nov 22 '22 15:11

Shina


I dont see why the following would not work... Make sure you are not setting widths or heights... post the full HTML.

<div class="table-responsive">
  <table class="table">
    ...
  </table>
</div>

[bootstrap3]

like image 25
Omar Avatar answered Nov 22 '22 15:11

Omar


Fizer Khan's answer on this page is correct. Just to add to it though, so that you only apply this when you absolutely want it in devices >768px, I'd recommend you create a custom CSS style in your own CSS file called something like:

.table-responsive-force {
    width: 100%;
    margin-bottom: 15px;
    overflow-y: hidden;
    overflow-x: scroll;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    border: 1px solid #DDD;
    -webkit-overflow-scrolling: touch;
}

Then you can just use it whenever you want to actually override Bootstrap's default behaviour.

like image 22
Henry Weber Avatar answered Nov 22 '22 15:11

Henry Weber