Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Border-Radius To Scrollbars with CSS

To put it simple, this is what i want (obtained on a Webkit Browser using -webkit-scrollbar) :

And this is what I get on Opera (Firefox doesn't apply the border radius to the scrollbar either, but still applies the border) :

Is there a simple way to make the border not disappear under the scrollbar ?

I dont need the fancy style of -webkit-scrollbar but i would like the page to look clean and symmetric...

like image 981
Yves Avatar asked May 21 '13 17:05

Yves


People also ask

How do you put a radius on a border in CSS?

CSS Syntaxborder-radius: 1-4 length|% / 1-4 length|%|initial|inherit; Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. If bottom-left is omitted it is the same as top-right. If bottom-right is omitted it is the same as top-left.

Can you style the scroll bar 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.

How do I make my scrollbar thinner CSS?

auto is the default value and will render the standard scrollbars for the user agent. thin will tell the user agent to use thinner scrollbars, when applicable. none will hide the scrollbar completely, without affecting the element's scrollability.


2 Answers

I've been having the same issue. It's not the most elegant of solutions but, simply put a smaller div inside your outer box so the scroll bar doesn't overlap the outer box.

Like this code copied from this pen:

.box {    height: 200px;    width: 250px;    border-radius: 10px;    border: 2px solid #666;    padding: 6px 0px;    background: #ccc;  }    .box-content {    height: 200px;    width: 250px;    overflow: auto;    border-radius: 8px;  }
<div class="box">    <div class="box-content">      <ol>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>        <li>test</li>      </ol>    </div>  </div>
like image 77
Mark Avatar answered Oct 12 '22 15:10

Mark


Put the content that needs to be scrolled in a div with overflow: auto. Around that content div put a div with your rounded corners and overflow: hidden.

Now you can see the scroll bar but its outer corners are hidden and are not disturbing the rounded corners of the outer div.

Example:

// Insert placeholder text  document.querySelector('.inner').innerHTML = 'Text<br>'.repeat(20);
.outer {    width: 150pt;    border: 1px solid red;    border-radius: 15pt;    overflow: hidden;  }    .inner {    height: 200px;    overflow-y: auto;  }
<div class="outer">      <div class="inner">          <!-- lots of text here -->      </div>  </div>
like image 28
SimpleDesign Avatar answered Oct 12 '22 13:10

SimpleDesign