treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Getting a scrollbar to display only when necessary

  • I have a div with an exact height. Inside of this div will be text, but I don't know how much (depends on the page). If there's more text than can fit in the div, I want it to display a scrollbar, but I only want the scrollbar to display in that particular case. So if all the text fits within the div, I don't want the scrollbar visible.

    Is this possible? I set a height on the div and used overflow: scroll, but this creates a persistent scrollbar that's merely disabled when all the text fits. I just want it to display only when you need to scroll. Any ideas?
  • Yes it is possible. Use this instead:

    overflow:auto;


    ;)
    Ashton Sanders
  • overflow: auto;

    EDIT.
    Too late again! :roll:
  • "apostrophe" said:
    Too late again! :roll:

    haha, we're taking turns beating eachother to the bunch lol
  • Wow...shows you what happens when I haven't had my morning coffee :D That's like the most obvious thing ever. Sorry I even made a post about this :lol: