Twitter Bootstrap navbar float right将div移动到新行 [英] Twitter Bootstrap navbar float right moves div to new line

查看:116
本文介绍了Twitter Bootstrap navbar float right将div移动到新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在导航栏的右侧创建一个部分。我使用div类navbar-right,应该将div向右移动,但是我得到了一个新行。

Hello I'm trying to create a section on the right of the navbar. I used the div class navbar-right which should float the div to the right, but I am getting a new line instead.

请参阅下面的代码&感谢!

See below for code & thanks!

 <div class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <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>
          <a class="navbar-brand" href="index.php">xxx</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="index.php">Home</a></li>
            <li><a href="about.php">About</a></li>
            <li><a href="contact.php">Contact</a></li>
          </ul>
        </div>
      <div class="navbar-right">
      <p>
        <b> '.$username.' </b> | Access Level: '.$level.' | <a href=logout.php>Logout</a>
      </p> 


      </div>
    </div>
  </div>


推荐答案

-bar,内容必须放在带有类的div内: navbar-header

In order to be placed at the top level of nav-bar, the contents must be placed inside of a div with the class: navbar-header

在div中声明注销链接:

So instead of declaring the logout link inside of the div:

<div class="navbar-right">

使用以下类:

<div class="navbar-header pull-right">

由于您需要 Brand pull-left ,您可以在顶部放置两个 navbar-header divs,拉向每个方向。像这样:

Since you'll want the Brand to pull-left, you can place two navbar-header divs right next to each other at the very top and have one pull to each direction. Like this:

<div class="navbar-header pull-left">     
    <a class="navbar-brand" href="index.php">xxx</a>
</div>
<div class="navbar-header pull-right">
    <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>

    <p class="navbar-text">
        <b> '.$username.' </b>
        <a href="logout.php" class="navbar-link">Logout</a>&nbsp;
    </p>  
</div>



jsFiddle



展开

已折叠

更新
根据Ram的评论,为了不让下拉菜单在小屏幕上不重叠,您必须清除左边的浮动像这样:

Update: As per Ram's comment, in order to not have the pull down menu not overlap on a small screen, you'll have to clear the left float like this:

.navbar-collapse.in,
.navbar-collapse.collapsing {
    clear: left;
}

这篇关于Twitter Bootstrap navbar float right将div移动到新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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