将按钮对齐到导航栏中文本的右侧

时间:2016-01-16 20:01:29

标签: html css twitter-bootstrap navbar

以下是我的代码到目前为止的标题,您将看到说明其帐户的文本以及注销按钮不会随文本右侧的按钮一起亮起。

<html>
<head>
    <title>DroneReg - File Section 333 Easy</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans|Source+Sans+Pro|Raleway' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="css/style.css">

    <!--Start Meta Content-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <a href="index.html" class="navbar-brand">DroneReg</a>
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <div class="collapse navbar-collapse navHeaderCollapse">
            <!--start difficulty-->
                    <p class="navbar-text navbar-right">Signed in as, <a href="#" class="navbar-link" style="color: white;">Mark Otto</a></p>
                <div>
                    <button type="button" class="btn btn-default navbar-btn pull-right"><a href="/logout">Logout</a></button>
                </div>                      
            </div>
        </div>
    </div>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

将您想要的代码包装在右侧:

<div class='nav navbar-nav navbar-right'>

像这样:

<div class="collapse navbar-collapse navHeaderCollapse">
    <div class='nav navbar-nav navbar-right'>
        <p class="navbar-text navbar-right">Signed in as, <a href="#" class="navbar-link" style="color: white;">Mark Otto</a></p>

        <button type="button" class="btn btn-default navbar-btn pull-right"><a href="/logout">Logout</a></button>
    </div>
</div>

答案 1 :(得分:0)

您需要从当前设置中删除导航栏右键和右键(请参阅文档中的Component Alignment以获取更多信息),然后在链接周围包裹<div class='nav navbar-nav navbar-right'>

如果您希望这些链接在768px下的视口上保持默认导航栏链接的对齐,则您需要添加自己的CSS,因为navbar-link通常用于默认导航组件之外的链接。 **如果您不想在全球范围内进行更改,请注意,如果您想要/需要为这些课程添加新课程。

  

对于使用不在常规导航栏中的标准链接的人   导航组件,使用.navbar-link类添加正确的   默认和反向导航栏选项的颜色。

*旁注:您也错过了navbar-header类,这将对结构产生重大影响。见Docs

请参阅FullPage上的工作示例代码段。

&#13;
&#13;
.navbar-nav .logout-btn a {
  text-decoration: none;
  color: #777;
}
.navbar-nav a.navbar-link {
  color: white;
}
@media (max-width: 767px) {
  .navbar-nav .logout-btn,
  .navbar-nav .navbar-text {
    margin-left: 15px;
  }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">

    <div class="navbar-header">
      <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="index.html" class="navbar-brand">DroneReg</a>
    </div>

    <div class="collapse navbar-collapse navHeaderCollapse">

      <div class='nav navbar-nav navbar-right'>
        <p class="navbar-text">Signed in as, <a href="#" class="navbar-link">Mark Otto</a>
        </p>
        <li>
          <button type="button" class="btn btn-default navbar-btn logout-btn"><a href="/logout">Logout</a>
          </button>
        </li>
      </div>

    </div>
  </div>
</div>
&#13;
&#13;
&#13;