Home >Web Front-end >CSS Tutorial >How to make scrollbar custom arrows work on mobile devices?

How to make scrollbar custom arrows work on mobile devices?

王林
王林forward
2023-09-17 19:25:121457browse

How to make scrollbar custom arrows work on mobile devices?

You may have noticed websites with unique scroll bars that give them a unique feel and look, as custom scroll bars are becoming more and more common. Custom scrollbars can be easily implemented in a few different ways. This article will use the simplest method, CSS.

We use CSS to enhance the visual appeal of the web pages in the application. Using CSS, we can now change the appearance of the scrollbar. Let’s see how to make scrollbar custom arrows work on mobile devices.

Make scrollbar custom arrows work on mobile devices

In the past, scrollbars on websites could be modified using non-standard CSS properties (like scrollbar-base-color), which you could apply to scrolling elements (like ) and do some pretty cool stuff. IE abandons this.

Custom scrollbars are available again today, albeit this time using WebKit. These properties now use "Shadow DOM" and have a vendor prefix (eg: -webkit-scrollbar). This has been around for a while.

To get more ideas on making scrollbar custom arrows work on mobile devices, let’s take a look at the following example.

Example

In the example below, we use webkit-scrollbar to make the scrollbar work on mobile devices and apply CSS to the scrollbar.

<!DOCTYPE html>
<html>
   <body>
      <style>
         div{
            max-width:400px;
            max-height:250px;
            overflow-y: scroll;
            overflow-x: hidden;
         }
         div::-webkit-scrollbar {
            width: 0.5em;
         }
         div::-webkit-scrollbar-track {
            -webkit-box-shadow: inset 0 0 2px rgba(1,1,1,0.4);
         }
         div::-webkit-scrollbar-thumb {
            background-color: #D5F5E3;
            outline: 1px solid #FBFCFC;
         }
      </style>
      <div id="tutorial">
         <img  src="https://www.tutorialspoint.com/about/images/about-mini-logo.jpg" alt="How to make scrollbar custom arrows work on mobile devices?" >
         Tutorials Point originated from the idea that there exists a class of readers
         who respond better to online content and prefer to learn new skills at their
         own pace from the comforts of their drawing rooms.The journey commenced with
         a single tutorial on HTML in 2006 and elated by the response it generated, we
         worked our way to adding fresh tutorials to our repository which now proudly
         flaunts a wealth of tutorials and allied articles on topics ranging from programming
         languages to web designing to academics and much more.
      </div>
   </body>
</html>

When the script executes, it will generate an output consisting of an image, some text, and a scrollable display on the web page.

Example

Consider the following example where we use webkit-scrollable to make content scroll with arrows on a web page.

<!DOCTYPE html>
<html>
   <body>
      <style>
         .visible-scrollbar,
         .mostly-customized-scrollbar {
            display: block;
            width: 300px;
            overflow: auto;
            height: 150px;
         }
         .invisible-scrollbar::-webkit-scrollbar {
            display: none;
         }
         .mostly-customized-scrollbar::-webkit-scrollbar {
            width: 300px;
            height: 8px;
            background-color:#7D3C98 ;
         }
         .mostly-customized-scrollbar::-webkit-scrollbar-thumb {
            outline: 1px solid #FBFCFC;
         }
      </style>
      <div class="visible-scrollbar">
         Mahendra Singh Dhoni born 7 July 1981, commonly known as MS Dhoni,
         is a former Indian cricketer and captain of the Indian national team
         in limited-overs formats from 2007 to 2017, and in Test cricket from
         2008 to 2014. He is also the current captain of Chennai Super Kings in
         the Indian Premier League. Under his captaincy, India won the 2007 ICC
         World Twenty20, the 2011 Cricket World Cup, and the 2013 ICC Champions
         Trophy, the most by any captain. He also led India to victory in the 2010
         and 2016 Asia Cup.
      </div>
   </body>
</html>

When you run the above script, an output window will pop up, displaying the text as well as the scrollable arrows displayed on the web page.

Example

Execute the code below and observe how we use webkit-scrollable to make custom scrolling.

<!DOCTYPE html>
<html>
   <body>
      <style>
         body {
            font-size: 15pt;
         }
         ::-webkit-scrollbar {
            width: 14px;
            border: 1px solid blue;
         }
         ::-webkit-scrollbar-button:single-button {
            background-color: fuchsia;
            height: 10px;
            width: 10px;
         }
         ::-webkit-scrollbar-thumb {
            background: maroon;
         }
         ::-webkit-scrollbar-track {
            background: silver;
         }
         ::-webkit-resizer {
            background: olive;
         }
      </style>
      <center>
         <img  src="https://upload.wikimedia.org/wikipedia/commons/3/3a/Ducatilogol.png" alt="How to make scrollbar custom arrows work on mobile devices?" >
         <p>Ducati is a group of companies, best known for manufacturing motorcycles
         and headquartered in Borgo Panigale, Bologna, Italy. The group is owned by
         German automotive manufacturer Audi through its Italian subsidiary
         Lamborghini, which is in turn owned by the Volkswagen Group.</p>
         <br>
         <p>In the 1930s and 1940s, Ducati manufactured radios, cameras, and
         electrical products such as razors. Ducati also made a marine binocular called the BIMAR for the Kriegsmarine during World War II, some of which
         were sold on the civilian market after the war.The Ducati Sogno was
         a half-frame Leica-like camera which is now a collector's item.</p>
      </center>
   </body>
</html>

When the script is executed, it will generate an output consisting of text, images, and custom scrollbars with CSS applied, and be displayed on the web page.

The above is the detailed content of How to make scrollbar custom arrows work on mobile devices?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:CSS width propertyNext article:CSS width property