4

I have a div with multiple cards which scrolls horizontally and by since I'm using

overflow-x: scroll;

I get a horizontal scroll bar under my div which I do want. That be said the bar takes up the width of the div but I'd rather have a more custom scroll bar which would only take up 50%-75% of the div.

Is there a way in css/js that would allow me to change the width of a HORIZONTAL scrollbar, all signs seem to point to no. If that's the case does anyone have experience creating a custom scrollbar.

My initial thought was to create an input slider which has the same number of ticks per card and scroll to each card onChange, but I can figure out if Window.scrollTo() works with horizontal scroll.

2 Answers 2

9

@ben

Yes, You can control height and width of your ScollBar using webkit.

::-webkit-scrollbar {
    width: 13px;
    height: 13px;
}

Here is the important link. https://webkit.org/blog/363/styling-scrollbars/

Sign up to request clarification or add additional context in comments.

Comments

0

How are you? I was having the same issue and I just figured out how yo solve it. In this other question Change the width of horizontal scroll bar it was suggested to use the following code

.inner::-webkit-scrollbar-track-piece:end {
  margin-right: 50px; 
}

.inner::-webkit-scrollbar-track-piece:start {
  margin-left: 50px;
}

This code scpecifically didn't work to me, but it gave me the thought "What if I added a margin to the ::-webkit-scrollbar-track css?", so I tried it and it worked! Here's how it looked like:

.slider-track-class::-webkit-scrollbar-track {
  background: #D8D8D8;
  border-radius: 10px;
  margin-right: 210px; <--
  margin-left: 210px; <--
}

I hope it helps (even tho you asked that 6yrs ago haha)

Edit: After some research I also found a similar solution in this question: How to change the width of horizontal scrollbar track?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.