Custom scrollbar cross-browser support
It is better to use javascript for scrollbars since they are not fully supported by all browsers. those libraries are examples to use:
- Simple-scrollbar
- SimpleBar
The following example uses simpleBar. see documentation above for options.
new SimpleBar(document.getElementById('container'));
#container { width: 300p; height: 350px; border: 1px solid #eee;}
.text {text-align: center; padding: 100px 50px;}
<link rel="stylesheet" href="https://unpkg.com/simplebar@latest/dist/simplebar.css" /><div id="container"> <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p><p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<script src="https://unpkg.com/simplebar@latest/dist/simplebar.min.js"></script>
Make scrollbar visible in mobile browsers
Try adding the below to your CSS, note that this is webkit specific:
Demo Fiddle
::-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;
}
How can I change the layout of the scroll bar on desktop monitors, as seen on tablets and phones?
use ::-webkit-scrollbar
in CSS
This is not supported in Firefox, Try SmoothScrollbarJs for firefox
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
directly copied from w3schools
CSS scrollbar style cross browser
Scrollbar CSS styles are an oddity invented by Microsoft developers. They are not part of the W3C standard for CSS and therefore most browsers just ignore them.
Scrollbars in mozilla
Since Firefox 64, is possible to use new specs for a simple Scrollbar styling (not as complete as in Chrome with vendor prefixes).
In this example is possible to see a solution that combine different rules to address both Firefox and Chrome with a similar (not equal) final result:
The key rules are:
For Firefox
.scroller {
overflow-y: scroll;
scrollbar-color: red green;
scrollbar-width: thin;
}
For Chrome
.scroller::-webkit-scrollbar-track
{
background-color: green;
}
.scroller::-webkit-scrollbar
{
width: 8px;
background-color: #F5F5F5;
}
.scroller::-webkit-scrollbar-thumb
{
background-color: red;
}
In the example linked are used also additional styles for Chrome to improve final style (such as rounded corners and shadows)
Related Topics
Why Won't Opera (11.00) Display Custom (@Font-Face) Fonts
CSS Horizontal Navigation Spacing
How to Enlarge The Svg Icon in Material-Ui Iconbuttons
Change Input Placeholder Color Darker
Bootstrap Container-Fluid - Remove Margins The Right Way (Overflow)
How to Align Text to The Middle of an Element with CSS in Twitter Bootstrap
Adding CSS Class to Multiple Elements
Fontello Glyph Font Odd Behaviour on Firefox, Shows Unicode Codes Instead of Icons
How to Change CSS Based on Mobile Device
Add Class to an Element in Angular 4
Reactjs How to Use Ref Inside Map Function
HTML.Actionlink with a Specified HTML Id