3

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
  • 763
  • 3
  • 8
  • 24

6 Answers6

10

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
  • 991
  • 7
  • 15
2

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

stanze
  • 2,372
  • 9
  • 13
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
  • 7,965
  • 3
  • 27
  • 62
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
  • 885
  • 1
  • 11
  • 22
1

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
  • 855
  • 9
  • 18
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,594
  • 33
  • 29
  • 34
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