CSS hide scroll bar if not needed
Set overflow-y
property to auto
, or remove the property altogether if it is not inherited.
Hide scroll bar, but while still being able to scroll
Just a test which is working fine.
#parent{
width: 100%;
height: 100%;
overflow: hidden;
}
#child{
width: 100%;
height: 100%;
overflow-y: scroll;
padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
box-sizing: content-box; /* So the width will be 100% + 17px */
}
Working Fiddle
JavaScript:
Since the scrollbar width differs in different browsers, it is better to handle it with JavaScript. If you do Element.offsetWidth - Element.clientWidth
, the exact scrollbar width will show up.
JavaScript Working Fiddle
Or
Using Position: absolute
,
#parent{
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
#child{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: -17px; /* Increase/Decrease this value for cross-browser compatibility */
overflow-y: scroll;
}
Working Fiddle
JavaScript Working Fiddle
Information:
Based on this answer, I created a simple scroll plugin.
how to hide a vertical scroll bar when not needed
overflow: auto
(or overflow-y: auto
) is the correct way to go.
The problem is that your text area is taller than your div. The div ends up cutting off the textbox, so even though it looks like it should start scrolling when the text is taller than 159px
it won't start scrolling until the text is taller than 400px
which is the height of the textbox.
Try this: http://jsfiddle.net/G9rfq/1/
I set overflow:auto on the text box, and made the textbox the same size as the div.
Also I don't believe it's valid to have a div
inside a label
, the browser will render it, but it might cause some funky stuff to happen. Also your div
isn't closed.
CSS hide scroll bar, but have element scrollable
You can hide it:
html {
overflow: scroll;
}
::-webkit-scrollbar {
width: 0px;
background: transparent; /* make scrollbar transparent */
}
For further information, see: Hide scroll bar, but while still being able to scroll
Allow scroll but hide scrollbar
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;
}
Related Topics
Netbeans CSS Not Hinting All Properties
Responsive Transparent Overlapping CSS Circles with Text Align Vertical and Center
How to Add Horizontal Scrollbar in a React Bootstrap Table
Ie9-11 Detecting Transform-Style: Preserve-3D
Vertically Align Div to Middle of Element
Space at Bottom of Div Containing Image
Why Do H1 Tags Not Need a Class or Id in The CSS
Ie11 Blurry Right Hand Edge of Div with Border-Radius
Bootstrap 4 Page Wide Header Bar Above Navbar
Overflow Scrolling with No Scrollbars
How to Prevent SASS from Merging Files Included via @Import
Font-Weight:900 Only Working in Firefox
Background Image Not Found from My CSS File
When Printing Page Table Rows/Cells Gets Split on Page Break
Chrome Will Increase The Font Size When Zooming Out