Bootstrap - 无法将NavBar右侧的折叠项目居中

时间:2015-07-07 18:17:01

标签: html css twitter-bootstrap

问题背景:

我有一个标准的Bootstrap可折叠NavBar,即pulled-right

问题:

这是非移动设备上的NavBar

enter image description here

这是向右拉,以允许这个所需的右对齐位置。

这是移动设备上的NavBar拼写错误:

enter image description here

**请注意,下拉菜单中的项目是对齐的,这是正确的,因为它向右拉,但我希望它们在移动设备上居中,同时保持它们在非移动设备上对齐

守则:

我认为在text-center列表中设置<ul>可以解决问题,但事实并非如此:

        <div class="navbar">
        <nav class="navbar navbar-default navbarColour" role="navigation" id="nav">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <img src="~/Images/DC.png" class="dc">
                </div>
                <div class="middleNavPadding">
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <div class="pull-right text-center">

                           ********Set text-center but this dosen't work********                                

                            <ul class="nav navbar-nav text-center">
                                <li><a href="#" class="scroll-link" data-id="Info">Services</a></li>
                                <li><a href="#" class="scroll-link" data-id="Mission">Our Mission</a></li>
                                <li><a href="#" class="scroll-link" data-id="Gallery">Projects Gallery</a></li>
                                <li><a href="#" class="scroll-link" data-id="Contact">Contact Us</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </nav>
    </div>

任何有关将这些<ul>列表元素设置为中心的帮助,但保持菜单项在非移动设备上正确使用将非常棒。

1 个答案:

答案 0 :(得分:0)

不应使用pull-right,而应使用navbar-right

只需将navbar-right添加到unordered-list,即可删除pull-right div,链接将以小型设备为中心。

工作example

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="navbar">
    <nav class="navbar navbar-default navbarColour" role="navigation" id="nav">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>
 <span class="icon-bar"></span>

                </button>
                <img src="~/Images/DC.png" class="dc">
            </div>
            <div class="middleNavPadding">
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav navbar-right text-center">
                            <li><a href="#" class="scroll-link" data-id="Info">Services</a>
                            </li>
                            <li><a href="#" class="scroll-link" data-id="Mission">Our Mission</a>
                            </li>
                            <li><a href="#" class="scroll-link" data-id="Gallery">Projects Gallery</a>
                            </li>
                            <li><a href="#" class="scroll-link" data-id="Contact">Contact Us</a>
                            </li>
                        </ul>
                </div>
            </div>
        </div>
    </nav>
</div>
&#13;
&#13;
&#13;