CSS vertical scrollbar padding left/right in UL possible?

CssScrollbar

Css Problem Overview


Is it possible to add padding or margin around the scrollbar item or scrollbar-track? I've tried and can only get padding top/bottom. Adding padding to the UL has no effect on scrollbar. Negative margins on scrollbar have no effect. Ideas? JS Fiddle here.

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

::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
-webkit-border-radius: 10px;
border-radius: 10px;
padding: 10px
}

::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(255,0,0,0.8); 
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(255,0,0,0.4); 

Css Solutions


Solution 1 - Css

You can see an example below, basically forget adding margin or padding there, just increase the width/height of scroll area, and decrease the width height of thumb/track.

Quoted from https://stackoverflow.com/questions/9226059/how-to-customise-custom-scroll

body {
  min-height: 1000px;
  font-family: sans-serif;
}

div#container {
  height: 200px;
  width: 300px;
  overflow: scroll;
  border-radius: 5px;
  margin: 10px;
  border: 1px solid #AAAAAA;
}

div#content {
  height: 1000px;
  outline: none;
  padding: 10px;
}

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

::-webkit-scrollbar-thumb {
  border: 4px solid rgba(0, 0, 0, 0);
  background-clip: padding-box;
  border-radius: 9999px;
  background-color: #AAAAAA;
}

<div id="container">
  <div id="content" contenteditable>
    Click to type...
  </div>
</div>

Solution 2 - Css

I created a margin-right effect using border-right on the scrollbar-thumb:

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

::-webkit-scrollbar-thumb {
  background: red;
  border-right: 4px white solid;
  background-clip: padding-box;
}

The scrollbar appears to have width 4px and margin-right 4px.

Here's a fiddle as well: https://jsfiddle.net/4kgvL93h/3/

Solution 3 - Css

This solution make a real space between content and scrollbar (if a scrollable element doesn't have a transparent background). Useful for window scrollbars.

.scroll {overflow:auto;}
.scroll::-webkit-scrollbar {
    width:16px;
    height:16px;
    background:inherit;
}
.scroll::-webkit-scrollbar-track:vertical {
    border-right:8px solid rgba(0,0,0,.2);
}
.scroll::-webkit-scrollbar-thumb:vertical {
    border-right:8px solid rgba(255,255,255,.2);
}
.scroll::-webkit-scrollbar-track:horizontal {
    border-bottom:8px solid rgba(0,0,0,.2);
}
.scroll::-webkit-scrollbar-thumb:horizontal {
    border-bottom:8px solid rgba(255,255,255,.2);
}
.scroll::-webkit-scrollbar-corner,
    .scroll::-webkit-resizer {background:inherit;
    border-right:8px solid rgba(255,255,255,.2); //optional
    border-bottom:8px solid rgba(255,255,255,.2); //optional
}

Solution 4 - Css

You can add a margin to the scrollbar track;

#someID ::-webkit-scrollbar-track{
  border-radius: 15px;
   margin: 40px;
  box-shadow: inset 7px 10px 12px #f0f0f0;
  
 }

Solution 5 - Css

Another important attribute to add vertical or horizontal margin:

::-webkit-scrollbar-track {
  margin: 0 30px;
}

Solution 6 - Css

Simply use the margin-block

::-webkit-scrollbar-track {
   box-shadow: inset 0 0 5px F2F2F2; 
   border-radius: 0px;
   margin-block: 15px;
}

#container{
    height:400px;
    background-color:white;
    overflow-y:scroll;
    border-radius:25px;  
}

#content{
    height:700px;
    background-color:yellow;
    padding:25px;
}

::-webkit-scrollbar{
    width: 5px;
}
  
  /* Track */
::-webkit-scrollbar-track{
    box-shadow: inset 0 0 5px F2F2F2; 
    border-radius: 0px;
    margin-block: 25px;
}
   
  /* Handle */
::-webkit-scrollbar-thumb{
     background: #8B8B8B; 
     border-radius: 27px;
     border: 4px solid rgba(0, 0, 0, 0);
 }

<div id="container">
  <div id="content">
    <br>
    Click to type...
    <br>
  </div>
</div>

Solution 7 - Css

With border-radius, neither box-shadow works properly nor does background-clip: padding-box.

I created a parent div on top of the div which needs scrolling. And fixed the height of parent div and put padding right in the child div. That worked well for my case.

<div class="parent h-10 overflow-scroll">
 <div class="scroll child pr-2">
     <!-- CONTENT -->
 </div>
</div> 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsandraquView Question on Stackoverflow
Solution 1 - CssBora Alp AratView Answer on Stackoverflow
Solution 2 - CssJordan DanielsView Answer on Stackoverflow
Solution 3 - CssHenry BrewerView Answer on Stackoverflow
Solution 4 - CssUsama MajidView Answer on Stackoverflow
Solution 5 - CssDror BarView Answer on Stackoverflow
Solution 6 - CssEstail SeView Answer on Stackoverflow
Solution 7 - CssRahul RathodView Answer on Stackoverflow