Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div expands past page height, but no scroll bar

Tags:

html

css

I have a div along the left side of my page for navigation links. Clicking on a header expands a subset of links. I have this div set to 100% of the page height so that the column takes up the entire left side of the page. The problem occurs when all of the sub categories are expanded. The content of the div runs off the bottom of the page, but doesn't add a scroll bar.

I tried setting the height to auto to see if that would fix the problem (ignoring the fact that it doesn't take up the whole left side), but that didn't fix it either.

So, what do I need to do to get a scroll bar when the div expands past the height of the page? Then have the scroll bar go away if it's not needed.

Thank you.

.leftNavigation {
display:block;
position:fixed;
width:200px;
height:100%;
top:140px;
left:0;
background-color:#f0f0f0;

}

<div class="leftNavigation">
    <p class="linkHeader" id="townLinksHeader"><img src="img/image.jpg" width="200" height="40" alt="Sunnyvale, CA" /></p>
    <div class="links" id="townLinks">
        <ul>
            <li><a href="">Link</a></li>
                    <li><a href="">Link</a></li>
                    <li><a href="">Link</a></li>
                    <li><a href="">Link</a></li>
        </ul>
    </div>

There are 4 paragraph/div combinations inside the left navigation div. Only the paragraph is show until it is clicked on. The links div is then show. When each of those is expanded, it runs off the bottom of the page but doesn't add a scroll bar.

Adding overflow:auto didn't change anything.

like image 285
navalhawkeye Avatar asked Jul 14 '11 15:07

navalhawkeye


People also ask

How do I force a div to scroll?

Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I get the scroll height of a div?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.

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.

How do I keep my div scrolled to the bottom?

The trick is to use display: flex; and flex-direction: column-reverse; The browser treats the bottom like its the top. Assuming the browsers you're targeting support flex-box , the only caveat is that the markup has to be in reverse order.


Video Answer


1 Answers

Does the side content div use fixed positioning? Because, that is usually why a scrollbar does not appear. Try setting the overflow:auto css style on that div to add a scrollbar when needed.

Update:

You have top:140px in there and height:100%. This is actually pushing the side div down below the page. If the expandable content is not taking up much space, then it will flow off the bottom of the page and no scrollbar will appear.

Try this:

.leftNavigation {
    display:block;
    position:fixed;
    width:200px;
    height:100%;
    top:0;
    left:0;
    padding-top:140px;
    overflow:auto;
    background-color:#f0f0f0;
}
like image 195
BumbleB2na Avatar answered Oct 17 '22 03:10

BumbleB2na