如何自动添加一个垂直滚动条到我的div? [英] how can I add a vertical scrollbar to my div automatically?
问题描述
我要为我的< Div>
添加垂直滚动条。我试过 overflow:auto
,但它不工作。我在Firefox和Chrome中测试了我的代码。
我在这里粘贴Div样式代码:
I want to add vertical scrollbar to my <Div>
. I've tried overflow:auto
, but it is not working. I've tested my code in Firefox and Chrome.
I'm pasting the Div style code here:
float:left;
width:1000px;
overflow: auto;
提前感谢。
推荐答案
您需要分配一些高度,以使 overflow:auto;
属性工作。
为了测试的目的,添加 height:100px;
并检查。
并且它会更好,如果你给予 overflow-y:auto;
而不是 overflow:auto;
,因为这使得元素只滚动垂直但不水平。
You need to assign some height to make the overflow: auto;
property work.
For testing purpose, add height: 100px;
and check.
and also it will be better if you give overflow-y:auto;
instead of overflow: auto;
, because this makes the element to scroll only vertical but not horizontal.
float:left;
width:1000px;
overflow-y: auto;
height: 100px;
如果你不知道容器的高度,并且想要显示垂直滚动条达到固定高度, 100px
,使用 max-height
,而不是 height
属性。
If you don't know the height of the container and you want to show vertical scrollbar when the container reaches a fixed height say 100px
, use max-height
instead of height
property.
有关详细信息,请阅读此 MDN文章 。
For more information, read this MDN article.
这篇关于如何自动添加一个垂直滚动条到我的div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!