I have a navbar on the right side of my website, but if i resize the screen like a tablet screen, the navbar goes on 2 rows.
My navbar html code is basic:
<div class="nav_div col-sm-offset-5 col-sm-7">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nav">
<ul class="nav navbar-nav navbar-center">
<li data-menuanchor="blablab" class="active"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>

I search to have an auto horizontal scrolling bar where the active tab is in the middle.
The problem is this: <div class="nav_div col-sm-offset-5 col-sm-7"></div>
your col-sm-7 is not large enough to hold your content when the view-port resizes so it pushes the content to a new row.
You can change it to something like this <div class="nav_div col-sm-offset-3 col-sm-9"> as an easy clean solution.
Two solutions with Demos:
<div class="nav_div col-sm-offset-3 col-sm-9">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nav">
<ul class="nav navbar-nav navbar-center">
<li data-menuanchor="blablab" class="active"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
CODEPEN DEMO 1
OR
You can manipulate the padding of your nav links in CSS, this allows you to still use <div class="nav_div col-sm-offset-5 col-sm-7"></div> without it breaking to a new row on screen resize.
.navbar-nav > li > a{
line-height: 50px;
padding: 0 5px;
}
CODEPEN DEMO 2
IF you want vertical scrolling youll need to decrease the size of your columns, however this is not a good way to structure a nav if you're using bootstrap.
<div class="nav_div col-sm-offset-5 col-sm-3">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Collect the nav links, forms, and other content for toggling -->
<ul class="nav navbar-nav navbar-center">
<li data-menuanchor="blablab" class="active"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
<li data-menuanchor="blablab"><a href="#blablab">blablab</a></li>
</ul>
</div><!-- /.container-fluid -->
</nav>
</div>
CSS:
.navbar{
max-height: 40px;
overflow-y: scroll;
}
CODEPEN DEMO 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With