Bootstrap菜单没有按下内容

时间:2014-12-25 08:48:05

标签: html css twitter-bootstrap

请原谅我的无知,我是新手。我有这个代码,我需要纠正,我无法弄清楚为什么菜单没有点击其他内容。以下是HTML和CSS代码片段



*:before,
   *:after {
     box-sizing: border-box;
   }
   .navbar-default .navbar-toggle {
     border-color: #ddd;
   }
   .navbar-toggle {
     background-color: transparent;
     background-image: none;
     border: 1px solid transparent;
     border-radius: 4px;
     float: right;
     margin-bottom: 8px;
     margin-right: 15px;
     margin-top: 8px;
     padding: 9px 10px;
     position: relative;
   }

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

<div class="row">
  <div class="col-md-12">
    <nav role="navigation" class="navbar navbar-default">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" class="navbar-toggle" type="button" aria-expanded="true">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a href="#" class="navbar-brand">
            <img alt="Harbor Real Estate" src="img/logo.png">
          </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="bs-example-navbar-collapse-1" class="navbar-collapse collapse in" aria-expanded="true" style="">

          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">About Us</a>
            </li>
            <li><a href="#">Buy</a>
            </li>
            <li><a href="#">Rent</a>
            </li>
            <li><a href="#">Landlords</a>
            </li>
            <li><a href="#">Property Management</a>
            </li>
          </ul>
        </div>
        <!-- /navbar-collapse -->
      </div>
      <!-- /container-fluid -->
    </nav>
  </div>
</div>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:2)

我认为它会将您的内容向下推,请参阅下面的示例。

我已将问题中的代码更改为代码段,并添加了jQuery和Bootstrap的CSS和JavaScript。由于导航栏的折叠行为依赖于jQuery和Bootstrap的JavaScript,这可能是缺失的。

另外两件事:

  1. 我已从in删除了班级<div id="bs-example-navbar-collapse-1" ...,以便默认情况下折叠导航栏

  2. 我已经删除了外部.row.col-md-12,因为他们不需要

  3. &#13;
    &#13;
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    
    <nav role="navigation" class="navbar navbar-default">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" class="navbar-toggle" type="button" aria-expanded="true">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a href="#" class="navbar-brand">
            <img alt="Harbor Real Estate" src="img/logo.png">
          </a>
        </div>
    
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="bs-example-navbar-collapse-1" class="navbar-collapse collapse" aria-expanded="true" style="">
    
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">About Us</a>
            </li>
            <li><a href="#">Buy</a>
            </li>
            <li><a href="#">Rent</a>
            </li>
            <li><a href="#">Landlords</a>
            </li>
            <li><a href="#">Property Management</a>
            </li>
          </ul>
        </div>
        <!-- /navbar-collapse -->
      </div>
      <!-- /container-fluid -->
    </nav>
    
    <div class="container">
      <div class="row">
        <div class="col-xs-12">Content</div>
      </div>
    </div>
    &#13;
    &#13;
    &#13;

答案 1 :(得分:1)

我有类似的问题,发现它是由于设置了包含我的导航栏的标头标签的固定高度。

我通过将特定的CSS放在媒体查询中来修复它,因此它只适用于更大的屏幕。

答案 2 :(得分:0)

您可以添加主j-query。 的jquery-1.11.1.min.js

在您的代码中使用此菜单

答案 3 :(得分:0)

穆罕默德哈萨姆。试试这个!的工作原理。

<head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
        <div class="row">
            <div class="col-md-12">
                <nav role="navigation" class="navbar navbar-default">
                    <div class="container-fluid">
                        <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header">
                            <button data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" class="navbar-toggle" type="button" aria-expanded="true">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <a href="#" class="navbar-brand">
                                <img alt="Harbor Real Estate" src="img/logo.png">
                            </a>
                        </div>

                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div id="bs-example-navbar-collapse-1" class="navbar-collapse collapse" aria-expanded="true">

                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="#">About Us</a>
                                </li>
                                <li><a href="#">Buy</a>
                                </li>
                                <li><a href="#">Rent</a>
                                </li>
                                <li><a href="#">Landlords</a>
                                </li>
                                <li><a href="#">Property Management</a>
                                </li>
                            </ul>
                        </div>
                        <!-- /navbar-collapse -->
                    </div>
                    <!-- /container-fluid -->
                </nav>
            </div>
        </div>

        <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</body>