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

Implementation of deploying war package project using Docker

To deploy war with Docker, you must use a contain...

How to set remote access permissions in MySQL 8.0

The previous article explained how to reset the M...

How to deploy Spring Boot using Docker

The development of Docker technology provides a m...

JS generates unique ID methods: UUID and NanoID

Table of contents 1. Why NanoID is replacing UUID...

VMware WorkStation 14 pro installation Ubuntu 17.04 tutorial

This article records the specific method of insta...

In-depth analysis of MySQL data type DECIMAL

Preface: When we need to store decimals and have ...

Detailed steps for deploying Tomcat server based on IDEA

Table of contents Introduction Step 1 Step 2: Cre...

CentOS 6 uses Docker to deploy Zookeeper operation example

This article describes how to use docker to deplo...

HTML discount price calculation implementation principle and script code

Copy code The code is as follows: <!DOCTYPE HT...

Analysis of Linux boot system methods

This article describes how to boot the Linux syst...

A brief discussion on MySQL event planning tasks

1. Check whether event is enabled show variables ...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

Detailed explanation of the use of Docker commit

Sometimes you need to install certain dependencie...

Analysis of rel attribute in HTML

.y { background: url(//img.jbzj.com/images/o_y.pn...