如何防止菜单在Bootstrap中堆叠在一起?

时间:2017-10-14 17:31:57

标签: html css

当我缩小窗口时,我希望菜单与中画面中的徽标保持在同一行。现在,它像Link to image一样堆叠。我如何解决它?

<nav class="navbar navbar-default">

    

<div class="navbar-header">
  <a class="navbar-brand" href="#">LOGO</a>
</div>

    <ul class="nav navbar-nav hidden-xs">
        <li><a href="#">Guides</a></li>
        <li><a href="#">Courses</a></li>
        <li><a href="#">Tutorials</a></li>
        <li><a href="#">Top Authors</a></li>

    </ul>

    <ul class="nav navbar-nav navbar-right" >
        <li><a href="#">Login</a></li>
        <li><a href="#">Sign Up</a></li>
    </ul>
 <!--collapse navbar -->    

2 个答案:

答案 0 :(得分:0)

很难说因为没有发布CSS,但您通常可以使用inline-block将元素放在同一行上。大致是:

.navbar-header {
  display:inline-block;
  vertical-align:middle;
  width:30%;
  text-align:left;
}
.nav {
  display:inline-block;
  vertical-align:middle;
  width:65%;
  text-align:right;
}

答案 1 :(得分:0)

这可能是由于遵守bootstrap标准导航栏的一些差异。以下是实施代码的代码段,但我将其应用于Bootstrap navbar documentation中提供的模板,如果您遇到任何问题,请与我们联系。

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav hidden-xs">
        <li><a href="#">Guides</a></li>
        <li><a href="#">Courses</a></li>
        <li><a href="#">Tutorials</a></li>
        <li><a href="#">Top Authors</a></li>

      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Login</a></li>
        <li><a href="#">Sign Up</a></li>
      </ul>
    </div>
  </div>
</nav>

JSFiddle Demo