Home  >  Article  >  Web Front-end  >  How to Ensure Scrollbars are Always Visible in Mobile Browsers?

How to Ensure Scrollbars are Always Visible in Mobile Browsers?

Linda Hamilton
Linda HamiltonOriginal
2024-11-10 21:06:03905browse

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>
#wrapper {
    overflow: scroll;
    -webkit-overflow-scrolling: touch;
    width: 500px;
    height: 200px;
}

#frameContent {
    width: 100%;
    height: 100%;
}

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;
}

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!

Statement:
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