Bootstrap:navbar-colapse div进入导航栏

时间:2017-09-25 09:56:26

标签: html css navbar bootstrap-4

这是我的问题: collapse problem

正如您可以看到我的导航栏折叠div进入导航栏区域。你可以帮我解决一下吗?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <a class="navbar-brand" href="#page-top">Title</a>
        <button class="navbar-toggle" data-toggle="collapse" data-target="#dropdown">
            Menu
        </button>
        <div class="collapse navbar-collapse" id="dropdown">
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <a href="#">Link 1</a>
                </li>
                <li>
                    <a href="#">Link 2</a>
                </li>
                <li>
                    <a href="#">Link 3</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

2 个答案:

答案 0 :(得分:1)

问题是你错过了添加navbar-header容器,这有助于隔离标题和子菜单。希望它有所帮助

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#page-top">Title</a>
      <button class="navbar-toggle" data-toggle="collapse" data-target="#dropdown">
                Menu
            </button></div>
    <div class="collapse navbar-collapse" id="dropdown">
      <ul class="nav navbar-nav navbar-right">
        <li>
          <a href="#">Link 1</a>
        </li>
        <li>
          <a href="#">Link 2</a>
        </li>
        <li>
          <a href="#">Link 3</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

在div id =“dropdown”中添加类.m-top-55,它适用于小布局

@media only screen and (min-width: 600px) {
    /* For tablets: */
    .m-top-55{
       margin-top:55px;
     }
}

这将解决您的问题。