Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css overflow scroll bar appears even when there is nothing to scroll

Tags:

html

jquery

css

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>
like image 245
cppit Avatar asked Apr 17 '12 17:04

cppit


People also ask

Why scroll bar is appearing when not needed?

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.

How do I turn off the scrollbar on my overflow scroll?

To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML.

Why is overflow scroll always visible?

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.


2 Answers

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.

like image 87
Erik Philips Avatar answered Oct 01 '22 19:10

Erik Philips


Try

overflow: auto

The link you provided is really complicated. Here is everything explained, I think much better: CSS-Tricks

like image 29
Jonny Burger Avatar answered Oct 01 '22 18:10

Jonny Burger