CSS Scrollbar Styling - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: CSS3 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=5) +--- Thread: CSS Scrollbar Styling (/showthread.php?tid=5190) |
CSS Scrollbar Styling - Qomplainerz - 07-26-2023 Description: You can customize the appearance of scrollbars in modern browsers using the ::-webkit-scrollbar pseudo-element. Example: <!DOCTYPE html> <html> <head> <title>CSS Scrollbar Styling Example</title> <style> /* Style the scrollbar track and thumb */ ::-webkit-scrollbar { width: 10px; } ::-webkit-scrollbar-track { background-color: #f1f1f1; } ::-webkit-scrollbar-thumb { background-color: #888; } </style> </head> <body> <div style="height: 300px; overflow-y: auto;"> <!-- Add long content to enable scrollbar --> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p> </div> </body> </html> Explanation: In this example, we use the ::-webkit-scrollbar pseudo-element to style the scrollbar in WebKit-based browsers (e.g., Chrome, Safari). The ::-webkit-scrollbar allows you to customize the scrollbar's width and appearance. ::-webkit-scrollbar-track styles the track (the background area behind the thumb), and ::-webkit-scrollbar-thumb styles the thumb (the draggable scrolling handle). |