Adam
Adam

Reputation: 3128

Always show scrollbar in Bootstrap table-responsive

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?

Upvotes: 22

Views: 33959

Answers (4)

rafael.js
rafael.js

Reputation: 600

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; 
}

Upvotes: 16

Aris
Aris

Reputation: 5057

You can enclose your table with:

<div style="overflow-x:scroll;">

Upvotes: 4

Stacey Schlenker
Stacey Schlenker

Reputation: 51

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;
}

Upvotes: 2

Shawn Taylor
Shawn Taylor

Reputation: 15740

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;}
}

Upvotes: 2

Related Questions