[css] UL or DIV vertical scrollbar

I have problem with vertical scrollbar on my page. I have lot of items inside ul inside div, I tried with overflow:auto in style for div but it doesn't help. How to add scrollbar vertical to ul or div ?

<div id="content">
<p>some text</p>
<ul>
<li>text</li>
.....
<li>text</li>
</div>

This question is related to css

The answer is


You need to define height of ul or your div and set overflow equals to auto as below:

<ul style="width: 300px; height: 200px; overflow: auto">
  <li>text</li>
  <li>text</li>

You need to set a height on the DIV. Otherwise it will keep expanding indefinitely.


Sometimes it is not eligible to set height to pixel values. However, it is possible to show vertical scrollbar through setting height of div to 100% and overflow to auto.

Let me show an example:

<div id="content" style="height: 100%; overflow: auto">
  <p>some text</p>
  <ul>
    <li>text</li>
    .....
    <li>text</li>
</div>