UL or DIV vertical scrollbar

Css

Css Problem Overview


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>

Css Solutions


Solution 1 - Css

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>

Solution 2 - Css

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

Solution 3 - Css

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>

Solution 4 - Css

this works for me :

<ul style="height: 100%; overflow: auto"
  <li>text1</li>
  ....
  <li>text100</li>
</ul>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDamirView Question on Stackoverflow
Solution 1 - CsssubositoView Answer on Stackoverflow
Solution 2 - CssRobustoView Answer on Stackoverflow
Solution 3 - CssStepUpView Answer on Stackoverflow
Solution 4 - CssE BusinessView Answer on Stackoverflow