Pure CSS to hide the scroll bar but still have the scrolling effect (mobile and PC)

Pure CSS to hide the scroll bar but still have the scrolling effect (mobile and PC)

Mobile

Mobile pages only need to be compatible with Chrome and Safari, so you can use the custom scroll bar pseudo-class selector ::-webkit-scrollbar to hide the scroll bar.

  .container::-webkit-scrollbar {
    display: none;
  }

PC

The compatibility requirements of the PC side are relatively higher, so you can try another method. The general idea is to wrap a parent container div outside the content div, set overflow: hidden, set display-x: hidden; display-y: auto for the content div; finally, set the width of the parent container div to be smaller than the width of the content div or set the margin-right of the content div to a negative value.

<div class="outer">
    <div class="content">
      <p>1111</p>
      <p>222</p>
      <p>333</p>
      <p>444</p>
    </div>
</div>
 .outer {
   width: 300px;
   height: 300px;
   overflow: hidden;
 
   .content {
     width: 330px;
     /*margin-right: -15px;*/
     height: 100%;
     overflow-x:hidden;
     overflow-y: auto;
     background: red;
     padding-top: 100px;
 
     p:not(:first-child) {
       margin-top: 100px;
     }
   }
 }

Summarize

The above is the pure CSS that I introduced to you to hide the scroll bar but still have the scrolling effect (mobile and PC). I hope it will be helpful to you!

<<:  Add ico mirror code to html (favicon.ico is placed in the root directory)

>>:  Detailed tutorial on deploying Apollo custom environment with docker-compose

Recommend

2 methods and precautions for adding scripts in HTML

How to add <script> script in HTML: 1. You c...

Detailed steps for installing JDK and Tomcat on Linux cloud server (recommended)

Download and install JDK Step 1: First download t...

Two ways to achieve horizontal arrangement of ul and li using CSS

Because li is a block-level element and occupies ...

In-depth understanding of the vertical-align property and baseline issues in CSS

vertical-align attribute is mainly used to change...

Analysis of the cause of docker error Exited (1) 4 minutes ago

Docker error 1. Check the cause docker logs nexus...

Implementation of Vue large file upload and breakpoint resumable upload

Table of contents 2 solutions for file upload Bas...

DD DT DL tag usage examples

We usually use the <ul><li> tags, but ...

How InnoDB implements serialization isolation level

Serialization implementation InnoDB implements se...

Detailed steps to build an independent mail server on Centos7.9

Table of contents Preface 1. Configure intranet D...

How to install mongodb 4.2 using yum on centos8

1. Make a repo file Refer to the official install...

Example of asynchronous file upload in html

Copy code The code is as follows: <form action...