[英]How do I make the scrollbar on a div only visible when necessary?
我有这个div:
<div style='overflow:scroll; width:400px;height:400px;'>here is some text</div>
即使文本没有溢出,滚动条也始终可见。 我想让滚动条仅在必要时可见 - 也就是说,只有当盒子中有足够的文本需要它们时才可见。 像textarea一样。 我该怎么做呢? 或者是我唯一的选择样式textarea所以它看起来像一个div?
使用overflow: auto
。 滚动条仅在需要时显示。
(旁注,您也可以仅指定x或y滚动条: overflow-x: auto
和overflow-y: auto
)。
试试这个:
<div style='overflow:auto; width:400px;height:400px;'>here is some text</div>
尝试
<div style='overflow:auto; width:400px;height:400px;'>here is some text</div>
尝试
<div id="boxscroll2" style="overflow: auto; position: relative;" tabindex="5001">
我发现有div的高度仍然显示,当它有文字或没有。 因此,您可以使用它来获得最佳效果。
<div style=" overflow:auto;max-height:300px; max-width:300px;"></div>
您可以尝试下面的一个:
<div style="width: 100%; height: 100%; overflow-x: visible; overflow-y: scroll;">Text</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.