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>
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.
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.
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%.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With