How to add marker to webkit CSS scrollbar?

Here's my site with the current webkit scrollbar: http://willwhitehead.com

I would like to create a gap between the scrollbar and the right edge of the screen.

How can I achieve this?

Thanks in advance,

Will

+3


source to share


3 answers


This is a terrible hack, but it seems to work. Use the selector ::-webkit-scrollbar

to make the bar fixed at x pixels. then set the left property to -px.

::-webkit-scrollbar {
    width: 10px; left:-100px;
}

      

Alternatively, you can do the following:

Give a ::-webkit-scrollbar

fixed width, say 30px, then set the border ::-webkit-scrollbar-thumb

as the padding you want to scroll so that it is on the right side of the screen. and set the background of the border to match the background color.

This will give the illusion that the scrollbar is floating right in the window, when in fact it is not. You can see this in the fiddle below.



body {
  background: blue;
}
*::-webkit-scrollbar {
  width: 30px;
}
*::-webkit-scrollbar-track {
  background: green;
  /* change me to blue to match the background */
}
*::-webkit-scrollbar-thumb {
  background: red;
  border: 10px yellow solid;
  /* change border color to blue to match the background */
}
      

<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
<p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
  the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
<p>
  <h5>The spirit of Rang De</h5>
  The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
  and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
      

Run codeHide result



However, probably the best thing to do is wrap all your content in a div container. Then change the css for the container to see:



body {
  background: blue;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
}
#container {
  position: absolute;
  left: 0;
  overflow-y: scroll;
  right: 60px;
  height: 100%;
  background: gold;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
}
::-webkit-scrollbar {
  width: 20px;
}
::-webkit-scrollbar-track {
  background: red;
}
::-webkit-scrollbar-thumb {
  background: green;
}
      

<div id="container">
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
  <p>The idea of Rang De was sown in the year 2006 - the same year when Mr. Yunus was awarded the Nobel Prize for his work with Grameen Bank. The motivation for starting Rang De was the belief that the peer to peer lending model could be leveraged to lower
    the cost of microcredit and reach out to under-served communities. RangDe.Org went live on January 26th 2008 (16:48 hrs to be precise!).</p>
  <p>
    <h5>The spirit of Rang De</h5>
    The name Rang De was decided after a lot of thought. It goes back to the patriotic struggle for Independence. We believe that a similar movement with the same kind of urgency is required to address poverty in India. The words Rang De also denote colour
    and exuberance and that is the significance we want our efforts to have for the people we reach out to.</p>
</div>
      

Run codeHide result


+8


source


There's another solution out there that fits easily into all projects. If you use a transparent border as a box and a box shadow with an inset to set its color, you will get the result you are hoping for.

For example:



::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    box-shadow: inset 0 0 10px 10px green;
    border: solid 3px transparent;
}

::-webkit-scrollbar-thumb {
    box-shadow: inset 0 0 10px 10px red;
    border: solid 3px transparent;
}

      

It might be an ugly scrollbar, but it serves as an example of what I mean.

+5


source


It's not your question, but in many cases it is easier to add padding-right

to the container of items rather than the scrollbar.

0


source







All Articles