How To Hide The Horizontal Scroll Bar While Scrolling In Mobile
I have some lists that I am displaying in one line on desktop but on mobile, I have to display the same but it should be horizontally scrollable by swiping. I tried the below code
Solution 1:
Using ::-webkit-scrollbar
CSS pseudo-element (for webkit browsers) and scrollbar-color
property (for Firefox)
.aboutlinks ul {
margin: 0;
padding: 0;
list-style: none;
}
.aboutlinks ul li {
display: inline-block;
margin: 15px;
border: 1px solid #000;
}
.aboutlinks ul li a {
padding: 6px 25px;
display: block;
}
@media all and (max-width: 768px) {
.aboutlinks ul {
display: flex;
overflow-x: auto;
}
.no-scrollbar {
scrollbar-color: transparent transparent;
}
.no-scrollbar::-webkit-scrollbar {
height: 0px;
}
.no-scrollbar::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 0 rgba(0, 0, 0, 0);
}
.no-scrollbar::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0);
-webkit-box-shadow: inset 0 0 0 rgba(0, 0, 0, 0);
}
.no-scrollbar::-webkit-scrollbar-thumb:window-inactive {
background: rgba(0, 0, 0, 0);
}
}
<div class="aboutlinks">
<ul class="smothscrollclass no-scrollbar">
<li><a href="" class="">ABCDE</a></li>
<li><a href="">FGHIJ</a></li>
<li><a href="">KLMNO</a></li>
<li><a href="">PQRST</a></li>
<li><a href="">UVWX</a></li>
<li><a href="">XY</a></li>
</ul>
</div>
Note: Use shift + mouse wheel
or touch gesture
to scroll
Solution 2:
overflow-x: hidden;
will fix your issue. on the body, not on the container. see the updated answer below:
.aboutlinks ul {
margin: 0;
padding: 0;
list-style: none;
}
.aboutlinks ul li {
display: inline-block;
margin: 15px;
border: 1px solid #000;
}
.aboutlinks ul li a {
padding: 6px 25px;
display: block;
}
@media all and (max-width: 768px) {
body{
overflow-x: hidden; // add this part
}
.aboutlinks ul {
display: flex;
//dont put any overflow here
}
}
<div class="aboutlinks">
<ul class="smothscrollclass">
<li><a href="" class="">ABCDE</a></li>
<li><a href="">FGHIJ</a></li>
<li><a href="">KLMNO</a></li>
<li><a href="">PQRST</a></li>
<li><a href="">UVWX</a></li>
<li><a href="">XY</a></li>
</ul>
</div>
Post a Comment for "How To Hide The Horizontal Scroll Bar While Scrolling In Mobile"