Iman
Iman

Reputation: 571

how to change width of scrollbar-track (line under ScrollBar)

I want to code scrollbar like this design:

enter image description here

it means width of -webkit-scrollbar-thumb must 5px and width of -webkit-scrollbar-track must 2px but i can't change width of -webkit-scrollbar-track independent of -webkit-scrollbar-thumb.

.main {
width: 100px;
height: 100px;
max-height: 100px;
background-color: #fff;
border: 1px solid red;
overflow-y: auto;
}

/* Scrollbar */

/* width */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #dddddd;
  /*box-shadow: inset 0 0 5px #dddddd;*/
  border-radius: 4px;
}

/* Handle */
::-webkit-scrollbar-thumb {
  background: #9e9e9e;
  border-radius: 4px;
}
<div class="main">
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
</div>

Upvotes: 1

Views: 7245

Answers (2)

Omid Mohsenzadeh
Omid Mohsenzadeh

Reputation: 96

for making scrollbar-track width thinner you can use border-left and border-right in ::-webkit-scrollbar-track with transparency and also change background to transparent and use box-shadow to change the color of track

.main {
width: 100px;
height: 100px;
max-height: 100px;
background-color: #fff;
border: 1px solid red;
overflow-y: auto;
}

/* Scrollbar */

/* width */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

/* Track */
::-webkit-scrollbar-track {
  background: transparent;
  box-shadow: inset 0 0 5px #dddddd;
  border-radius: 4px;
  border-left: 1.5px solid transparent;
  border-right: 1.5px solid transparent;
}

/* Handle */
::-webkit-scrollbar-thumb {
  background: #9e9e9e;
  border-radius: 4px;
}
<div class="main">
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
 <div>test</div>
</div>

Upvotes: 3

NET
NET

Reputation: 21

you can add 'border-left' and 'border-right' to both track and thumb..

check this:

.main {
  width: 150px;
  height: 150px;
  max-height: 250px;
  background-color: #fff;
  border: 1px solid red;
  overflow-y: auto;
}

/* Scrollbar */

/* width */
::-webkit-scrollbar {
  width: 20px;
}

/* Track */
::-webkit-scrollbar-track {
  background: #dddddd;
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-left: 9px solid white;
  border-right: 9px solid white;
}

/* Handle */
::-webkit-scrollbar-thumb {
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
  background: #9e9e9e;
  border-radius: 10px;
  border-left: 5px solid white;
  border-right: 5px solid white;
}

Upvotes: 1

Related Questions