Grow your CSS skills. Land your dream job.

Getting a scrollbar to display only when necessary

  • # May 7, 2009 at 11:07 am

    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?

    # May 7, 2009 at 11:48 am

    Yes it is possible. Use this instead:

    Code:
    overflow:auto;

    ;)
    Ashton Sanders

    # May 7, 2009 at 11:52 am

    overflow: auto;

    EDIT.
    Too late again! :roll:

    # May 7, 2009 at 11:55 am
    "apostrophe" wrote:
    Too late again! :roll:

    haha, we’re taking turns beating eachother to the bunch lol

    # May 7, 2009 at 1:31 pm

    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:

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".