我从导航栏容器中删除了5个链接中的2个,现在它已经不再居中了?

时间:2016-08-19 21:54:13

标签: css twitter-bootstrap

我从互联网上获得了一个引导主题,左侧有一个徽标图像的导航栏,中间居中的页面链接和右侧的社交媒体帐户徽标。原始模板有5个链接,它们完全位于中间。我并不需要那么多,所以我删除了其中的2个,但现在一切都没有了。这是导航栏的中间部分:

<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>

包含上述部分的完整导航栏包括:

<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>

3 个答案:

答案 0 :(得分:2)

你可以减少col-md的大小并偏移菜单:

<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>

答案 1 :(得分:0)

CSS类col-md-8 col-xs-12 nav-wrap可能是确定导航栏部分宽度的类。查看CSS文件,看看是否可以减少一个或多个类的宽度。

答案 2 :(得分:0)

尝试添加2个空行项目,如下所示:

<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>
        <li></li>
        <li></li>
    </ul>
</div>