Apply Border-Radius To Scrollbars with CSS

2019-02-08 04:45发布

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...

3条回答
走好不送
2楼-- · 2019-02-08 05:01

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>

查看更多
仙女界的扛把子
3楼-- · 2019-02-08 05:04

I've been having the same issue. It's not the most elegant of solutions but this is what I did...

Simply put a smaller div inside your outer box so the scroll bar doesn't overlap the outer box. Like this http://codepen.io/DeadWhisky/pen/eKFha

查看更多
爷的心禁止访问
4楼-- · 2019-02-08 05:27

Would be nice if you could supply a fiddle. Nevertheless, you shoud try changing the box-sizing on the container to border-box (if not already done):

box-sizing: border-box;
查看更多
登录 后发表回答