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.

4
  • set to .s overflow:scroll; to make it scrollable Commented Jun 10, 2015 at 9:33
  • That's exactly what it's supposed to do. Change to overflow:auto instead Commented Jun 10, 2015 at 9:34
  • use .s{overflow-y:scroll;} . try it Commented Jun 10, 2015 at 9:36
  • Similar question stackoverflow.com/questions/16670931/… Commented Jun 10, 2015 at 11:05

7 Answers 7

13

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>
Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

2

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

Comments

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;

Comments

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/

Comments

0

Another way could be:

  1. put overflow:hidden to container
  2. document.getElementbyId().scroll = true
  3. Then you can do scroll

1 Comment

There's lots of help available in the help center, including editing help. Why not start off with the tour?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.