52

I have a div with element styles like this:

 <div style="overflow-y: auto; max-height: 300px;">< id="DivTableContainer" ></div>

I need to allow scrolling along the y-axis when it becomes higher than 300px, this works fine. But I need to set "visiblity = false" to scroll bar itself.

I tried to use this element style:

overflow-y: hidden;

While it hides the scroll bar, it also disallows scrolling. Is there a way to get scrolling without having the scrollbar visible?

3
  • 1
    Try nanoScroller, it shows the scroll bar when you hover. Commented Aug 2, 2014 at 13:44
  • Hi @Jake745. I edited your question, because it was not comprehensible before. Can you please check that it still asks what you wanted to ask? If not, please leave a comment or edit it yourself :). Commented Aug 2, 2014 at 18:37
  • Good work Jonas. Thanks for your support :) Commented Aug 4, 2014 at 4:08

3 Answers 3

40

It's better, if you use two div containers in HTML .

As Shown Below:

HTML:

<div id="container1">
    <div id="container2">
        // Content here
    </div>
</div>

CSS:

 #container1{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

 #container2{
    height: 100%;
    width: 100%;
    overflow: auto;
    padding-right: 20px;
}
Sign up to request clarification or add additional context in comments.

1 Comment

31

I know this is an oldie but here is a quick way to hide the scroll bar with pure CSS.

Just add

::-webkit-scrollbar {display:none;}

To your id or class of the div you're using the scroll bar with.

Here is a helpful link Custom Scroll Bar in Webkit

2 Comments

doesnt work on Firefox though ;)
correct, Firefox doesn't have ::webkit .. you would have to use some javascript or jquery to hide it or try using some css to style it.
11

Try this:

HTML:

<div id="container">
    <div id="content">
        // Content here
    </div>
</div>

CSS:

#container{
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#content{
    width: 100%;
    height: 99%;
    overflow: auto;
    padding-right: 15px;
}

html, body{
    height: 99%;
    overflow:hidden;
}

JSFiddle Demo

Tested on FF and Safari.

2 Comments

Good idea imbondbaby.
-1... So you are going to accept the answer, then unaccept it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.