How do I get the scrollbar to overlay div content?
already tried to use track
with transparent background, but it does not work
::-webkit-scrollbar-track {background: transparent}
remains the same, occupying part of the content
.faq-body {
width: 250px;
height: 400px;
background: #fff;
overflow: scroll;
border: 1px solid #7b7d7f;
}
.faq-body::-webkit-scrollbar {
width: 16px;
}
.faq-body::-webkit-scrollbar-thumb {
background-color: #7b7d7f;
border: 5px solid #fff;
border-radius: 10rem;
}
.faq-body::-webkit-scrollbar-track {
position: absolute;
right: -3rem;
top: -50rem;
background: transparent;
}
.faq-question {
padding: 20px;
border-bottom: 1px solid #000;
line-height: 1.3;
color: #15191b;
font-size: 0.8rem;
}
<div class="faq-body">
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
<div class="faq-question">
Question
</div>
</div>
Can someone help me?
We call those overlay scrollbars and they are either partially or fully transparent while sitting on top of the page content. In other words, unlike classic scrollbars that take up physical real estate on the screen, overlay scrollbars sit on top of the screen content.
An element's scrollbar gutter is the space between the inner border edge and the outer padding edge, where the browser may display a scrollbar. If no scrollbar is present, the gutter will be painted as an extension of the padding.
Show scroll bars in Word and Excel for WindowsClick File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.
For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.
There are two ways to get a similar result:
Javascript Lib
Use http://grsmto.github.io/simplebar/
https://jsfiddle.net/w0a5Ls6h/
Pro:
Cons:
or
Only CSS
<style>
.faq-body {
width: 250px;
height: 400px;
background: #fff;
overflow-y: scroll;
border: 1px solid #7b7d7f;
}
.faq-body::-webkit-scrollbar {
width: 7px;
}
.faq-body::-webkit-scrollbar-thumb {
background-color: rgba(0,0,0,0.4);
border-radius: 10rem;
border: 1px solid #fff;
}
.faq-body::-webkit-scrollbar-track-piece:start {
background: transparent;
}
.faq-body::-webkit-scrollbar-track-piece:end {
background: transparent;
}
.faq-question {
padding: 20px;
border-bottom: 1px solid #000;
line-height: 1.3;
color: #15191b;
font-size: 0.8rem;
}
</style>
Cons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With