您好我正在尝试在导航栏的右侧创建一个部分。我使用了div类navbar-right,它应该将div向右浮动,但我得到的是新行。
请参阅下面的代码&谢谢!
<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>
答案 0 :(得分:15)
要放置在导航栏的顶层,内容必须放在具有类的div内:navbar-header
因此,而不是在div中声明注销链接:
<div class="navbar-right">
请改用以下课程:
<div class="navbar-header pull-right">
由于您需要Brand
到pull-left
,因此您可以在顶部将两个navbar-header
div放在彼此旁边,并向每个方向拉一个。像这样:
<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>
</p>
</div>
<强>扩展强>
<强>折叠强>
<强>更新强>: 根据Ram的评论,为了不让下拉菜单在小屏幕上重叠,你必须像这样清除左浮动:
.navbar-collapse.in,
.navbar-collapse.collapsing {
clear: left;
}
答案 1 :(得分:1)
而不是,
<div class="navbar-right">
<p>
<b> '.$username.' </b> | Access Level: '.$level.' | <a href=logout.php>Logout</a>
</p>
</div>
使用,
<p class="pull-right">
<b> '.$username.' </b> | Access Level: '.$level.' | <a href=logout.php>Logout</a>
</p>