简体   繁体   中英

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.

 .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/

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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