I am using overflow:scroll like the code below, the issue I am having is that even if there is no text the scroll bar still shows.
demo on w3schools: http://www.w3schools.com/cssref/tryit.asp?filename=trycss_overflow
you see that even if you cant scroll horizontally (left or right) there is still a scrolling bar. I am trying to have it where the scrollbar doesn't appear if there is nothing to scroll to.hope this makes sense
<style type="text/css">
div.scroll {
background-color: #00FFFF;
width: 100px;
height: 100px;
overflow: scroll;
}
</style>
<p>overflow:scroll</p>
<div class="scroll">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div>
By default, a scroll bar will appear when the content is too long. Page authors can override this in a number of ways, for example: overflow-y: hidden => cut off content that is too long. overflow-y: scroll => always show a scroll bar even when it's not needed.
To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML.
Make sure overflow is set to "scroll" not "auto." With that said, in OS X Lion, overflow set to "scroll" behaves more like auto in that scrollbars will still only show when being used. So if any the solutions above don't appear to be working that might be why. You can style it accordingly if you don't like the default.
I think you are looking for overflow: auto
.
Mozilla's Documentation on Overflow
The overflow CSS property is shorthand for the overflow-x and overflow-y properties, and specifies what to do when content is too large to fit in its block formatting context.
The options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area.
auto
Depends on the user agent. If content fits inside the padding box, it looks the same as visible, but still establishes a new block-formatting context. Desktop browsers like Firefox provide scrollbars if content overflows.
Try
overflow: auto
The link you provided is really complicated. Here is everything explained, I think much better: CSS-Tricks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With