问题背景:

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

问题:

这是非移动设备上的NavBar



将其向右拉,以实现此所需的右对齐插入。

这是在移动设备上折叠的NavBar



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

代码:

我认为在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>列表元素设置为居中但在非移动设备上保持菜单项向右拉的任何帮助都很好。

最佳答案

不要使用pull-right,而应该使用navbar-right。只需将navbar-right放在unordered-list中,然后删除pull-right div,链接将集中在小型设备上。



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

关于html - Bootstrap-无法在向右拉导航栏的情况下将折叠的物品居中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31276360/

10-10 13:00