Example code for hiding element scrollbars using CSS

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being able to scroll on any element?

First, if you need to hide the scroll bar and display it when the content overflows, you only need to set the overflow: auto style. If you want to completely hide the scroll bar, just set overflow: hidden, but this will make the element content unscrollable. To date, there is no CSS rule that allows an element to hide the scrollbar while still allowing the content to scroll. This can only be achieved by setting the scrollbar style for specific browsers.

Firefox

For Firefox, we can set the scrollbar width to none:

scrollbar-width: none; /* Firefox */

Internet Explorer

For IE, we need to use the -ms-prefix attribute to define the scrollbar style:

-ms-overflow-style: none; /* IE 10+ */

Chrome and Safari browsers

For Chrome and Safari browsers, we have to use the CSS scrollbar selector and then hide it using display:none:

::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}

Note: When you want to hide the scroll bar, it is best to set the overflow display to auto or scroll to ensure that the content is scrollable.

Example

We use the above CSS properties and overflow to implement the following example - hiding the horizontal scroll bar while allowing the vertical scroll bar:

.demo::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
.demo {
  scrollbar-width: none; /* firefox */
  -ms-overflow-style: none; /* IE 10+ */
  overflow-x:hidden;
  overflow-y: auto;
}

Summarize

The above is the sample code for using CSS to hide the scroll bar of elements. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  How to choose and use PNG, JPG, and GIF as web image formats

>>:  IDEA2021 tomcat10 servlet newer version pitfalls

Recommend

Sample code for generating QR code using js

Some time ago, the project needed to develop the ...

Basic usage of JS date control My97DatePicker

My97DatePicker is a very flexible and easy-to-use...

MySql8 WITH RECURSIVE recursive query parent-child collection method

background When developing a feature similar to c...

HTML 5 Reset Stylesheet

This CSS reset is modified based on Eric Meyers...

MySQL 8.0.15 installation and configuration graphic tutorial under Win10

This article records the installation and configu...

MySQL series 9 MySQL query cache and index

Table of contents Tutorial Series 1. MySQL Archit...

MySQL Series 8 MySQL Server Variables

Tutorial Series MySQL series: Basic concepts of M...

Example of how to exit the loop in Array.forEach in js

Table of contents forEach() Method How to jump ou...

Vue.js implements tab switching and color change operation explanation

When implementing this function, the method I bor...

JavaScript functional programming basics

Table of contents 1. Introduction 2. What is func...

Use js in html to get the local system time

Copy code The code is as follows: <div id=&quo...

Detailed explanation of how to synchronize data from MySQL to Elasticsearch

Table of contents 1. Synchronization Principle 2....

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...

Detailed steps for deepin20 to install NVIDIA closed-source drivers

Step 1: Install the deep "graphics driver&qu...