Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I style horizontal scrollbar by CSS?

Tags:

html

css

I styled my vertical scrollbars with the following code:

::-webkit-scrollbar {   width: 4px;   border: 1px solid #d5d5d5; }  ::-webkit-scrollbar-track {   border-radius: 0;   background: #eeeeee; }  ::-webkit-scrollbar-thumb {   border-radius: 0;   background: #b0b0b0; } 

Now, my vertical scrollbar looks like this:

enter image description here

However, my horizontal scrollbar looks like this :

enter image description here

How can I set a 2-4px height for it?

like image 487
Romanoti Avatar asked Jun 02 '17 17:06

Romanoti


People also ask

How do I style a horizontal scrollbar in CSS?

For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.

How do I customize my horizontal scroll bar?

For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.

Can you style a scrollbar CSS?

As of 2020, 96% of internet users are running browsers that support CSS scrollbar styling. However, you will need to write two sets of CSS rules to cover Blink and WebKit and also Firefox browsers. In this tutorial, you will learn how to use CSS to customize scrollbars to support modern browsers.


1 Answers

::-webkit-scrollbar {   height: 4px;              /* height of horizontal scrollbar ← You're missing this */   width: 4px;               /* width of vertical scrollbar */   border: 1px solid #d5d5d5; } 

since logically one cannot force a vertical scrollbar to be a certain height (since dictated by the positioned parent) - therefore such height property is to target the horizontal's scrollbar height - and vice-versa (width for the width of the vertical scrollbar.).

like image 181
Roko C. Buljan Avatar answered Sep 19 '22 09:09

Roko C. Buljan