CSS UL 或 DIV 垂直滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4102832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:07:03  来源:igfitidea点击:

UL or DIV vertical scrollbar

css

提问by Damir

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 ?

我的页面上的垂直滚动条有问题。我在 ul 中的 div 中有很多项目,我尝试在 div 样式中使用 overflow:auto ,但没有帮助。如何将滚动条垂直添加到 ul 或 div ?

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

回答by subosito

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

您需要定义 ul 或 div 的高度并将溢出设置为 auto 如下:

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

回答by Robusto

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

您需要在 DIV 上设置高度。否则它将无限期地扩大。

回答by StepUp

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 overflowto auto.

有时无法将高度设置为像素值。但是,可以通过将 div 的高度设置为100%overflowto来显示垂直滚动条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>