引导3:保持导航栏项目在折叠之外,不换行到新行? [英] Bootstrap 3: keep navbar items outside the collapse without wrapping to a new line?

查看:2017
本文介绍了引导3:保持导航栏项目在折叠之外,不换行到新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用一些帮助让我的Bootstrap 3导航栏,当折叠时看起来不错。

I could use some help getting my Bootstrap 3 navbar to look right when collapsed.

如果这是一个重复的问题,但好的长时间搜索没有产生我需要的答案。

Apologies if this is a duplicate question but a good long search hasn't yielded the answers I need.

我已经创建了一个基于Bootstrap演示代码的响应式导航栏。在它,有一个40x40的图像和一个地球字形链接到下拉菜单,我已经右对齐,从导航折叠中省略。

I've created a responsive navbar based on the Bootstrap demo code. In it, there's a 40x40 image and a globe glyph that link to dropdown menus, which I've right-aligned and omitted from the nav Collapse.

不幸的是,当导航收缩时,40x40和地球标志符显示在一个新行上,我不想要。

Unfortunately, the 40x40 and globe glyph appear on a new line when the nav collapses, which I don't want.

当导航合拢时,完美的布局将是40x40和地球仪与我的品牌形象,折叠按钮等在同一行显示;右对齐,并且不包含在崩溃中。

My perfect layout when the nav collapses would be for the 40x40 and globe to appear on the same line as my brand image, the collapse button etc; right aligned, and not contained in the collapse.

感谢您提供的任何建议!

Thank you for any advice you can give!

代码如下:

    <nav class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-hd-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a href="index.php"><img class="navbar-brand img-responsive" src="http://placehold.it/138x38" alt="Logo"></a>
    </div>
     <div class="navbar-right">
        <ul class="nav"  style="float: right; display: inline-block !important">
            <li class="dropdown pull-right">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img src="http://placehold.it/40x40" alt="Profile Image" style="display: inline-block !important"/><b class="caret grey"></b></a>
                <ul class="dropdown-menu">
                    <li class="dropdown-header">Hello</li>
                    <li class="divider"></li>
                    <li><a href="">Thing 1</a></li>
                    <li class="divider"></li>
                    <li><a href="">Thing 2</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav"   style="float: right; display: inline-block !important">
            <li class="dropdown pull-right">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-globe grey"></span><b class="caret grey"></b></a>
                <ul class="dropdown-menu">
                    <li style="padding: 10px"><p>News</p></li>
                </ul>
            </li>
        </ul>


         <div class="collapse navbar-collapse navbar-hd-collapse">
             <ul class="nav navbar-nav">
                 <li class="active"><a href="">Product</a></li>
                 <li><a href="">Other Product</a></li>
                 <li><a href="">Third Product</a></li>
             </ul>
         </div>
    </nav>

JS Fiddle在这里:http://jsfiddle.net/CaraGee/q8br8/

JS Fiddle is here: http://jsfiddle.net/CaraGee/q8br8/

推荐答案

制作一个折叠div对齐到左边:
和div中的非可折叠元素与右边对齐
像这样:

make a the collapse div with the align to the left: and the non collapsable elements inside a div with the align to the right like this:

<div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">Project name</a>
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <!-- THIS WILL COLLAPSE-->
            <div class="navbar-collapse collapse navbar-left">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="#contact">Contact</a></li>
                </ul>
            </div>
            <!-- THIS WILL NOT COLLAPSE -->
            <div class="nav navbar-nav" >
                <form class="navbar-form navbar-right">
                    <div class="form-group">
                        <input type="text" placeholder="Usuario" class="form-control">
                    </div>
                    <div class="form-group">
                        <input type="password" placeholder="Contraseña" class="form-control">
                    </div>
                    <button type="submit" class="btn btn-success">Conectarse</button>
                </form>
            </div>
        </div>
    </div>

这篇关于引导3:保持导航栏项目在折叠之外,不换行到新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆