21

I am using .table-responsive class to make my Bootstrap tables responsive and it's working fine but the user doesn't have any indicator that the table is horizontally scrollable!

How can I make the horizontal scrollbar always displayed, not only after the user actually starts scrolling.

Edit

The solution mentioned here almost works: Always show scrollbars in iPhone/Android:

::-webkit-scrollbar {
    -webkit-appearance: none;
}

::-webkit-scrollbar:vertical {
    width: 12px;
}

::-webkit-scrollbar:horizontal {
    height: 12px;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, .5);
    border-radius: 10px;
    border: 2px solid #ffffff;
}

::-webkit-scrollbar-track {
    border-radius: 10px;  
    background-color: #ffffff; 
}

Its problem is showing the scrollbars everywhere, not just to .table-responsive class. How I can restrict it?

Community
  • 1
  • 1
Adam
  • 2,948
  • 10
  • 43
  • 74

4 Answers4

15

Sorry for being 5 years late, but you must add .table-responsive before the pseudo-element, like this:

.table-responsive::-webkit-scrollbar {
    -webkit-appearance: none;
}

.table-responsive::-webkit-scrollbar:vertical {
    width: 12px;
}

.table-responsive::-webkit-scrollbar:horizontal {
    height: 12px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, .5);
    border-radius: 10px;
    border: 2px solid #ffffff;
}

.table-responsive::-webkit-scrollbar-track {
    border-radius: 10px;  
    background-color: #ffffff; 
}
rafael.js
  • 550
  • 6
  • 16
4

You can enclose your table with:

<div style="overflow-x:scroll;">
Aris
  • 4,643
  • 1
  • 41
  • 38
2

If you add overflow-x:scroll to the <768 breakpoint, it will always show the scrollbar below 768px. But as a caveat, it will also show when there is nothing to scroll (i.e. if the table is narrower than 768px)...

@media(max-width:767px){
  .table-responsive{overflow-x:scroll;}
}
Shawn Taylor
  • 15,590
  • 4
  • 32
  • 39
  • 1
    I tried this in both Firefox and Chrome, to no effect. The rule is not being overridden. What else could it be? – DatsunBing May 27 '15 at 22:19
2

Another thing you could do is to use a pseudo element.

.<classname>:before {
    padding: 2px 5px;
    content: "Swipe left to read more";
    color: #fff;
    background: #333;
}
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131