本文介绍了如何使div上的滚动条仅在必要时可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个div:
<div style='overflow:scroll; width:400px;height:400px;'>here is some text</div>
即使文本不会溢出,滚动条也始终可见.我想使滚动条仅在必要时可见-即,仅在框中需要它们的文本时才可见.就像textarea一样.我该怎么做呢?还是我唯一选择设置文本区域样式以使其看起来像div的选项?
The scrollbars are always visible, even though the text does not overflow. I want to make the scrollbars only be visible when necessary - that is, only visible when there is enough text in the box that they are needed. Like a textarea does. How do I do this? Or is my only option to style a textarea so it looks like a div?
推荐答案
使用overflow: auto
.滚动条仅在需要时显示.
Use overflow: auto
. Scrollbars will only appear when needed.
(旁注,您也可以只为x或y滚动条指定:overflow-x: auto
和overflow-y: auto
).
(Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto
and overflow-y: auto
).
这篇关于如何使div上的滚动条仅在必要时可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!