Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't hide scrollbar when using overflow: auto

Tags:

html

css

I have this CSS:

.div {
    background-color: red;
    position: relative;
    height: 414px;
    overflow: auto;
    width: 902px;
    margin: 0px auto;
}

I tried with overflow-y: hidden;, scrollbar disappear but scroll isn't working. Hope you understand what I want... Also, should I use auto or scroll? With auto I see horizontal bar too.

Here is JSFiddle: http://jsfiddle.net/sp95S/
Thanks!

like image 525
youmotherhaveapples Avatar asked Dec 07 '13 22:12

youmotherhaveapples


People also ask

How do I stop my scroll bar from appearing?

To hide the scrollbar and disable scrolling, we can use the CSS overflow property. This property determines what to do with content that extends beyond the boundaries of its container. To prevent scrolling with this property, just apply the rule overflow: hidden to the body (for the entire page) or a container element.

How do I make the scrollbar disappear when not needed?

Under Display options for this workbook, clear or select the Show horizontal scroll bar check box and Show vertical scroll bar check box to hide or display the scroll bars.

How do you make the scrollbar only visible when overflow?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).


2 Answers

Create an inner div: http://jsfiddle.net/sp95S/1/

.div {
    background-color: red;
    position: relative;
    height: 214px;
    overflow: hidden;
    width: 452px;
    margin: 0px auto;
}
#inner{
    width: 100%;
    overflow: auto;
    height: 100%;
    padding-right: 15px;
}
like image 133
user1121487 Avatar answered Sep 27 '22 19:09

user1121487


It seems like you want to have the page still scroll without the scrollbar showing.

This has been answered here a couple of times already:

  • hide scrollbar while still able to scroll with mouse/keyboard
  • Hiding the scrollbar on an HTML page

Basically you can use javascript (or jquery, though you don't necessarily need it). On webkit browsers, there is a function to hide the scrollbars:

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

but it won't work for firefox or internet explorer or opera.

like image 35
ERose Avatar answered Sep 27 '22 19:09

ERose