简体   繁体   English

如何始终在 div 上显示垂直滚动条

[英]How to always show the vertical scroll bar on div

I want to always show the vertical scroll bar on the div irrespective of the height.无论高度如何,我都想始终在 div 上显示垂直滚动条。

 .myclass { overflow-y: scroll; }
 <div class="myclass"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div>

But the scroll bar is disabled.但是滚动条被禁用。 Here is my JSFiddle: https://jsfiddle.net/9jgp5ncm/这是我的 JSFiddle: https ://jsfiddle.net/9jgp5ncm/

How can I always show the vertical scroll bar.如何始终显示垂直滚动条。 Please help.请帮忙。

You try to change browser behavior what is on the native scroll-bars not possible.您尝试更改浏览器行为,这在本机滚动条上是不可能的。

You can add an inner-div in your myClass diff and make it 5 pixel bigger as your outer diff so the scroll element is activated.您可以在 myClass diff 中添加一个内部 div 并使其比外部 diff 大 5 个像素,以便激活滚动元素。

Or use one of the thousands library for custom scrollers.或者使用数千个库之一来自定义滚动条。

But honestly I have no clue why you want to change it for your project.但老实说,我不知道你为什么要为你的项目改变它。

You should add height to your container:您应该为容器添加高度:

.myclass
{
  overflow-y: scroll;
  height: 200px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM