Hi Everyone....

I have a div which contains an unordered list... After some user actions i load the div with a longer list i.e. containing more list items than the previous one. I use jquery's higher level ajax functions to do this.

The problem is when i load it through ajax the list elements overflow the div's bottom portion and some of them get's displayed out of the div.

I haven't set any heights for the containing div assuming that it will expand to accomodate any future longer lists.

I'll post the code below and will be extremely grateful if someone figures this out....

#sidebar1 {
    float: left;
    width: 15%; /* since this element is floated, a width must be given */
    background: #FFE8BF; /* the background color will be displayed for the length of the content in the column, but no further */
    padding: 15px 0; /* top and bottom padding create visual space within this div  */

<div id="sidebar1">

                <div class="sidebarmenu">

                 <ul id="sidebarmenu1">
                            <a href="#" id="loadHotel" >
                            <a href="#" id="loadCountry">

                            <a href="#" id="loadCity">


            </div>  <!-- end #sidebar1 -->

I load the list elements into the <ul id = "sidebarmenu1"> Hope i'm clear... Thanks a lot in advance....

3 answers

Dave 5

Are you floating any of the list items? You might try using the Clearfix method on the containing div to see if that sorts it out.

Answered over 9 years ago by Dave
  • I agree. It sounds like a floating issue.. Jens Hedqvist over 9 years ago
danwellman 5600

If a clearing solution doesn't work, you could try using jQuery's height() method, which returns the computed height of an element, then use the result to set the height of the container, ensuring it is long enough for the content.

You could use the success handler of whichever AJAX method you're using to do something like this:

Answered over 9 years ago by danwellman

Try floating the inner elements to the left, just like the containing div. Another method might be to use overflow: auto; although this occasionally has some issues.

Smashing Magazine had a very thorough article on this recently. Here's the link:


Answered over 9 years ago by Nick Pettit