CSS overflow scrolling and hidden scrollbar (iOS)
As seen here: https://forum.webflow.com/t/how-do-i-hide-the-browser-scrollbar-from-appearing-when-a-user-scrolls/59643/5
::-webkit-scrollbar {
display: none; // Safari and Chrome
}
seems to work.
As of May 2020, this was the only solution that allowed me to hide the horizontal scrollbar on iOS Safari - including when the website is installed on the home screen as a PWA.
The idea is to make your container slightly higher than it needs to be with a padding-bottom
, and to clip out that extra space where to scrollbar appears with clip-path
.
Here is a snippet:
.scroll-container {
width: 100%;
padding-bottom: 30px;
white-space: nowrap;
overflow: auto;
clip-path: inset(0 0 30px 0);
}
.item {
display: inline-block;
width: 150px;
height: 300px;
margin-right: 20px;
background-color: #ddd;
border-radius: 20px;
}
<div class="scroll-container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
This does have the disadvantage of adding extra space, which does push down the other elements below. This issue could be negated / prevented with a negative margin. It wouldn't be super clean, but it would work.
Ex.:
.scroll-container { margin-bottom: -30px; }
I just played with this CodePen and it seems that if you set the background-color
to transparent
for all three properties below (and in this example also remove box-shadow
s), the scrollbar is not visible at all:
#style-1::-webkit-scrollbar-track {
// -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.1);
background-color: transparent;
}
#style-1::-webkit-scrollbar {
background-color: transparent;
}
#style-1::-webkit-scrollbar-thumb {
// -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: transparent;
}
This was tested in Chrome Desktop, Chrome for Android, and iOS Safari (v8.4) on an iPhone 6+.
I would however recommend for user experience (usability/accessibility) to keep the scrollbar visible though, as even I, knowing what I was doing, got a bit confused when there was no scrollbar.