How to Ensure Scrollbars are Always Visible in Mobile Browsers?

Linda Hamilton
Release: 2024-11-10 21:06:03
Original
917 people have browsed it

How to Ensure Scrollbars are Always Visible in Mobile Browsers?

How to Display a Scrollbar in Mobile Browsers

Despite CSS properties like "overflow:auto" and "overflow:visible" revealing scrollbars on desktop browsers, mobile browsers often conceal them until scrolling begins. This article addresses how to make scrollbars consistently visible on mobile devices, even without using ineffective jQuery libraries.

Consider the following HTML and CSS code:

<div>
Copy after login
#wrapper {
    overflow: scroll;
    -webkit-overflow-scrolling: touch;
    width: 500px;
    height: 200px;
}

#frameContent {
    width: 100%;
    height: 100%;
}
Copy after login

To make the scrollbar always visible on mobile devices, add the following CSS:

::-webkit-scrollbar {
    -webkit-appearance: none;
}

::-webkit-scrollbar:vertical {
    width: 12px;
}

::-webkit-scrollbar:horizontal {
    height: 12px;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, .5);
    border-radius: 10px;
    border: 2px solid #ffffff;
}

::-webkit-scrollbar-track {
    border-radius: 10px;
    background-color: #ffffff;
}
Copy after login

This code, specific to the WebKit browser engine, modifies the scrollbar's appearance, ensuring its visibility on mobile devices.

The above is the detailed content of How to Ensure Scrollbars are Always Visible in Mobile Browsers?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template