apdm apdm - 3 months ago 17
CSS Question

I removed 2 of 5 links from a navbar container, and now it's no longer centered?

I got a bootstrap theme from the internet, with a navbar that has a logo image on the left side, links to pages centered in the middle, and social media account logos on the right side. The original template had 5 links, and they were perfectly centered in the middle. I didn't need that many so I deleted 2 of them, but now everything is off kilter. Here is the middle part of the navbar:

<div class="col-md-8 col-xs-12 nav-wrap">
<ul class="nav navbar-nav">
<li><a href="#owl-hero" class="page-scroll">Home</a></li>
<li><a href="#portfolio" class="page-scroll">Projects</a></li>
<li><a href="#contact" class="page-scroll">Contact</a></li>
//Originally had 2 more links
</ul>
</div>


And the full navbar with the above part included:

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
<a class="navbar-brand" href="#"><img src="img/logo/logo.png" class="img-responsive" alt="logo"></a>
</div>
<div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
<div class="col-md-8 col-xs-12 nav-wrap">
<ul class="nav navbar-nav">
<li><a href="#owl-hero" class="page-scroll">Home</a></li>
<li><a href="#portfolio" class="page-scroll">Projects</a></li>
<li><a href="#contact" class="page-scroll">Contact</a></li>
</ul>
</div>
<div class="social-media hidden-sm hidden-xs">
<ul class="nav navbar-nav">
<li><a href="#"><i class="fa fa-facebook"></i></a></li>
<li><a href="#"><i class="fa fa-linkedin"></i></a></li>
</ul>
</div>
</div>
</div>
</nav>

Answer

you can just reduce the size for col-md and offset the menu :

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" 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>
        <a class="navbar-brand" href="#"><img src="img/logo/logo.png" class="img-responsive" alt="logo"></a>
    </div>
    <div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
        <div class="col-md-6 col-md-offset-4 col-xs-12 nav-wrap">
            <ul class="nav navbar-nav">
                <li><a href="#owl-hero" class="page-scroll">Home</a></li>
                <li><a href="#portfolio" class="page-scroll">Projects</a></li>
                <li><a href="#contact" class="page-scroll">Contact</a></li>
            </ul>
        </div>
        <div class="social-media hidden-sm hidden-xs">
            <ul class="nav navbar-nav">
                <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                <li><a href="#"><i class="fa fa-linkedin"></i></a></li>
            </ul>
        </div>
    </div>
</div>