Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll LI items in a fixed height UL?

Here is my example HTML.

And I want to have scroll for my LI items.

Which are of 2 levels. Means, I want to apply class on every UL.

So how can I do that. By using JQuery or CSS tweaking.

PS: I am using this example.

<ul id="nav" class="dropdown">
<li class="dir">
    Item_Root
    <ul>
        <li class="dir">
            Item_1_Level
            <ul>
                <li>Item_Level_2</li>
                <li>Item_Level_2</li>
                <li>Item_Level_2</li>
                <li>.... up to N items</li>
            </ul>
        </li>
        <li>Item_Level_1</li>
        <li>Item_Level_1</li>
        <li>Item_Level_1</li>
        <li>Item_Level_1</li>
        <li>.... up to N items</li>
    </ul>
</li>

 </ul>  
like image 773
Tahir Avatar asked Jan 05 '11 12:01

Tahir


People also ask

How do I add a scroll in UL Li?

defining the max-height to 63 will make the ul behave normally if it stays under 63px high, but if it exceeds that, it will overflow and show a scroll bar. If you want to show more items, just increase the max-height to the desired height.

How do I make my scroll height?

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.

How do you make a scrollable list in HTML?

CSS / HTML :min-height:200px;height:200px; max-height:auto; Here min-height is necessary to define. It tells that once the content exceed the 200px limit then show the scrollbar. max-height should be auto or 100%.

How do I scroll vertically?

For vertical scrollable bar use the x and y axis. 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.


1 Answers

With your posted mark-up, and the best guess I could make of the intent of your question (your title doesn't really match the example you linked to), I came up with this:

#nav {
    width: 12em;
    height: 20em;
    line-height: 2em;
    border: 1px solid #ccc;
    padding: 0;
    margin: 0;
    overflow: scroll;
    overflow-x: hidden;
}

li {
    border-top: 1px solid #ccc;
}

ul ul {
    text-indent: 1em;
}

ul ul ul {
    text-indent: 2em;
}

JS Fiddle Demo.

like image 79
David Thomas Avatar answered Oct 21 '22 23:10

David Thomas