Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make scroll bar overlay content

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

enter image description here

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

like image 285
Yung Silva Avatar asked Sep 10 '19 00:09

Yung Silva


People also ask

What is overlay scroll bar?

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.

What is scroll bar gutter?

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.

How do I get my scroll bar to show?

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.

How do I make my vertical overflow scroll?

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.


1 Answers

There are two ways to get a similar result:

Javascript Lib

Use http://grsmto.github.io/simplebar/

https://jsfiddle.net/w0a5Ls6h/

Pro:

  • Browser compatibility
  • Satisfactory result

Cons:

  • 3rd javascript

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:

  • Browser compatibility
  • Similar result but not satisfactory
like image 137
Vitor Avanço Avatar answered Sep 22 '22 08:09

Vitor Avanço