Javascript 在 HTML 中添加滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5414786/
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-23 17:06:39  来源:igfitidea点击:

Adding Scrollbars in HTML

javascripthtmlcssscrollbar

提问by alex

This is kind of a really nooby question, and I think I already know the answer, but:

这是一个非常菜鸟的问题,我想我已经知道答案了,但是:

Can you add Scrollbars to the side of a <div>?

您可以将滚动条添加到 a 的一侧<div>吗?

回答by alex

CSS

CSS

div {
   height: 100px;
   overflow: auto;
}

jsFiddle.

js小提琴

You give an explicit height so the divdoesn't expand to fit its content.

你给出一个明确的高度,这样div它就不会扩展以适应它的内容。

If you only want horizontal or vertical scrolling, use overflow-xand overflow-yrespectively.

如果您只想水平或垂直滚动​​,请分别使用overflow-xoverflow-y

If down the track you want the extra content to be hidden, use overflow: hidden.

如果您希望隐藏额外的内容,请使用overflow: hidden.

The default for overflowproperty is visible.

overflow属性的默认值是visible

回答by ckaufman

Css:

css:

overflow:auto;

or force the scroll area even when content doesn't overflow by:

或强制滚动区域,即使内容没有溢出:

overflow-y:scroll;

回答by Developer

This will add scroll bar in a div

这将在 div 中添加滚动条

 <div style="overflow:auto; height:556px;width:564px;">
 </div>