2

I want the vertical scrollbar for my div to be invisible, but still allow vertical scrolling.

  1. I've tried using overflow-y: hidden but that disables scrolling.

  2. I've tried webkit element::-webkit-scrollbar but that affects horizontal scrollbars too.

I would have thought that webkit's :vertical state would allow me to do it but it doesn't do anything. See codepen: (https://codepen.io/numberjak/pen/MWgOMqd)

Other questions look at BOTH scrollbars, I just care about ONE scrollbar.

<div class="scroll"><div class="large-content"/></div>
.scroll {
  overflow: auto;
  max-width: 20rem;
  max-height: 20rem;
  background-color: black;
}

.scroll::-webkit-scrollbar:vertical {
  display: none;
}

.large-content {
  min-width: 100rem;
  min-height: 100rem;
  background-color: red;
}
numberjak
  • 1,065
  • 4
  • 13
  • 28
  • Possible duplicate of [Hide scroll bar, but while still being able to scroll](https://stackoverflow.com/questions/16670931/hide-scroll-bar-but-while-still-being-able-to-scroll) – 9841pratik Sep 05 '19 at 09:04
  • Not a duplicate, that hides all scrollbars – numberjak Sep 05 '19 at 09:11
  • This will be really hard (if not impossible) to do, especially if you want crossbrowser support, as scrollbar-styling is still pretty basic. I'd suggest you use a JS scrollbar, e.g. https://github.com/buzinas/simple-scrollbar – elveti Sep 05 '19 at 10:04

2 Answers2

0

Try this css code..

css

.large-content {
    background-color: red;
    width: 100%;
    height: 100%;
}
Manikandan2811
  • 831
  • 4
  • 9
0

You can do the following to hide scrollbars:

-webkit- (Chrome, Safari, newer versions of Opera):

.scoll::-webkit-scrollbar { width: 0 !important; }

-moz- (Firefox):

.scroll { overflow: -moz-scrollbars-none; }

-ms- (Internet Explorer +10):

.scroll { -ms-overflow-style: none; }

Important points to be considered before hiding the scroll bar:

  1. Preferably hide scrollbars only if and when all content is visible else the user may skip the content.
  2. Avoid horizontal scrolling on web pages and do not hide horizontal scroll bar as they can make content difficult to read
  3. If at all, hiding scroll is required: Display all important information above the fold. Users may often decide if they want to stay or not on what they can see without scrolling.

Reference

Halden Collier
  • 845
  • 7
  • 18