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

Mysql practical exercises simple library management system

Table of contents 1. Sorting function 2. Prepare ...

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

JS implementation of carousel example

This article shares the specific code of JS to im...

mysql5.6.8 source code installation process

Kernel: [root@opop ~]# cat /etc/centos-release Ce...

How to create a swap partition file in Linux

Introduction to Swap Swap (i.e. swap partition) i...

Docker-compose installation yml file configuration method

Table of contents 1. Offline installation 2. Onli...

About using Alibaba's iconfont vector icon in Vue

There are many import methods on the Internet, an...

Vue implements multiple selections in the bottom pop-up window

This article example shares the specific code of ...

Usage of Vue filters and timestamp conversion issues

Table of contents 1. Quickly recognize the concep...

How to compile and install opencv under ubuntu

Easy installation of opencv2: conda install --cha...

Two ways to connect WeChat mini program to Tencent Maps

I've been writing a WeChat applet recently an...

The correct way to use Homebrew in Linux

Many people use Linux Homebrew. Here are three ti...