Explanation
I have this Bootstrap's navigation bar that has a horizontal responsive menu, but it is showing a horizontal scrollbar. I've listed below some attempts to hide/remove (and still scroll) this scrollbar, but nothing works properly.
Attempt 1: Use overflow-x: hidden
, but then it won't scroll horizontally.
Attempt 2: Use ::-webkit-scrollbar {display: none;}
, but it only works on webkit's based browsers.
Attempt 3: As suggested in this answer, I tried to use this code below, but then the submenu's (when navigation is expanded) size was changed and the scrollbar was still in there. You can see it in this fiddle.
#parent{
height: 100%;
width: 100%;
overflow: hidden;
}
#child{
width: 100%;
height: 100%;
overflow-y: scroll;
padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
}
/*I changed overflow-y to overflow-x and padding-right to padding-bottom*/
Is there any way that works on most browsers?
Sample code
You can also see on JSFiddle.
#navigation {
background-color: rgba(230, 104, 92, 1);
}
.navbar-toggle i, .navbar-brand, .navbar-nav li a {
color: #fff;
}
.nav {
white-space: nowrap;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
</head>
<body id="body">
<header id="navigation" class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<i class="fa fa-bars fa-2x" aria-hidden="true"></i>
</button>
<a class="navbar-brand" href="#body">
Logo
</a>
</div>
<nav class="collapse navbar-collapse navbar-right" role="navigation">
<ul id="nav-js" class="nav navbar-nav">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
<li><a href="#">Item3</a></li>
<li><a href="#">Item4</a></li>
<li><a href="#">Item5</a></li>
<li><a href="#">Item6</a></li>
<li><a href="#">Item7</a></li>
<li><a href="#">Item8</a></li>
<li><a href="#">Item9</a></li>
<li><a href="#">Item10</a></li>
<li><a href="#">Item11</a></li>
<li><a href="#">Item12</a></li>
<li><a href="#">Item13</a></li>
<li><a href="#">Item14</a></li>
<li><a href="#">Item15</a></li>
</ul>
</nav>
</div>
</header>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Thanks in advance,
Luiz.