5

I can't scroll vertical in the div when I set overflow:hidden to it. I don't understand why.

HTML:

<div class="s">
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
<p>lorem ispum<br/></p>
 </div>

CSS:

 .s{
        overflow:hidden;
        height:200px;
        border:1px solid red;
    }
    body{
        height:100%;
    }

I make a test JsFiddle to show the error.

JsFiddle

Update:

I need to hide the scrollbar, but i can't scroll if it's hidden.

Joci93
  • 803
  • 3
  • 10
  • 24

7 Answers7

12

If you want to hide the scroll bar but you wish to let it scroll, you can have a container with overflow:hidden; and a child container with overflow-y:scroll, and hide the scroll bar with negative right margin.

See the fiddle

The CSS :

.cont{
    position:relative;
    overflow:hidden;
    height:200px;
    width:100%;
    border:1px solid red;
}
.s{
    overflow-y:scroll;
    height:200px;
    width:100%;
    position:absolute;
    right:-30px;
}

The HTML :

<div class="cont">
    <div class="s">
        <p>Content</p>
    </div>
</div>
Billy
  • 1,031
  • 8
  • 15
2

Replace your overflow: hdden with overflow-x: hidden;

stanze
  • 2,456
  • 10
  • 13
2

Try

.s {
  scrollbar-width: none;
  -ms-overflow-style: none;
   overflow: hidden;
  }

.s::-webkit-scrollbar {
  display: none;
  overflow: hidden;
  }

One for firefox and other for chrome

Pran R.V
  • 1,015
  • 12
  • 21
1

I don't know if you mean vertical or not, but if you want to be able to scroll horizontally but vertically hidden, change it to:

overflow-y:hidden;

likewise if you want to be the other way around, change to:

overflow-x:hidden;
Jamie Barker
  • 8,145
  • 3
  • 29
  • 64
1

You're setting the overflow property of the containing <div class='s'> to hidden. As the name suggests, this will hide any containing content that spills out of the <div> dimensions.

Try setting:

.s{
    overflow-y:scroll;
    height:200px;
    border:1px solid red;
}

JS Fiddle: http://jsfiddle.net/ccrhpbp5/3/

LeDoc
  • 935
  • 2
  • 12
  • 24
0

Another way could be:

  1. put overflow:hidden to container
  2. document.getElementbyId().scroll = true
  3. Then you can do scroll
David Buck
  • 3,752
  • 35
  • 31
  • 35
Martin
  • 1
  • 1
  • There's lots of help available in the [help], including [editing help](https://stackoverflow.com/editing-help). Why not start off with the [tour]? – David Buck Aug 05 '20 at 19:39
0

I wrapped my entire content inside the body in a div. And then in the content class in CSS, I gave max-height and hid the scrollbar.

<body>
  <div class="content">
    <!-- My actual content -->
  </div>
</body>
.content {
    max-height: 100vh;
    overflow-y: scroll;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.content::-webkit-scrollbar {
    width: 0;
}

For me, the max-height element was the key attribute.

ssindher11
  • 168
  • 1
  • 7