Bootstrap菜单居中问题

时间:2015-02-03 19:42:43

标签: html css twitter-bootstrap

我试图将菜单放在中心位置,但我无法使其正常工作。当我更改浏览器/屏幕大小时,其位置会中断。 (我知道当尺寸太小时它会缩小)菜单包含三个部分。左侧部分,搜索框和右侧部分。 我希望我的菜单能够居中,但到目前为止还无法实现。

这是我的代码。 http://jsfiddle.net/bhtf8f09/

图片:http://i.imgur.com/XBTlpq3.png

HTML

<nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse" id="myNavbar">
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"> &nbsp;<span class="glyphicon glyphicon-align-justify pull-right"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Account Settings <span class="glyphicon glyphicon-cog pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">User stats <span class="glyphicon glyphicon-stats pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Messages <span class="badge pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Favourites Snippets <span class="glyphicon glyphicon-heart pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Sign Out <span class="glyphicon glyphicon-log-out pull-right"></span></a></li>
                        </ul>
                    </li>
                    <!--<li><a href="#"><span class="glyphicon glyphicon-align-justify"></span></a></li>-->
                    <li><a href="#"><span class="glyphicon glyphicon-home"></span> Anasayfa</a></li>
                    <li><a href="#"><span class="glyphicon glyphicon-user"></span> Profil</a></li>
                    <!--<li><a href="#"><span class="glyphicon glyphicon-user"></span> Keşfet</a></li>-->
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Keşfet &nbsp;<span class="glyphicon glyphicon-chevron-down pull-right"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Account Settings <span class="glyphicon glyphicon-cog pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">User stats <span class="glyphicon glyphicon-stats pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Messages <span class="badge pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Favourites Snippets <span class="glyphicon glyphicon-heart pull-right"></span></a></li>
                            <li class="divider"></li>
                            <li><a href="#">Sign Out <span class="glyphicon glyphicon-log-out pull-right"></span></a></li>
                        </ul>
                    </li>
                </ul>
                <div class="col-sm-3 col-md-3 pull-left">
                    <form class="navbar-form" role="search">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Arama" name="srch-term" id="srch-term">
                            <div class="input-group-btn">
                                <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                            </div>
                        </div>
                    </form>
                </div>
                <ul class="nav navbar-nav">
                    <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
                    <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
                </ul>
            </div>
        </div>
    </nav>

CSS

html {
    width:100%;
    height:100%;
}

.collapse, .navbar-collapse {
    width:55% !important;
    margin:0 auto !important;
}

.navbar {
    border-radius:0;
    background-color:#bf5b5b;
}

.navbar-inverse .navbar-nav > li > a {
    color:#fadaaf;
}

.navbar a {
    color:#337ab7;
}


.glyphicon-chevron-down {
    margin-top:3%;
}

1 个答案:

答案 0 :(得分:1)

您需要在元素上使用.col-md-*.col-sm-*以及.col-xs-*。这个标记可以大大简化,并且可以进一步改进使用的引导程序。尝试创建将所有内容放在.container中,以应用居中的边距。