Bootstrap 4 Navbar链接未正确定位

时间:2017-11-11 13:19:02

标签: javascript css angular bootstrap-4

请查看问题的图片:

enter image description here

如上所示,NavBar链接全部堆叠而不是正确显示在一行中。

这是我的HTML代码:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <!-- build:css(.) styles/vendor.css -->
    <!-- bower:css -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
    <!-- endbower -->
    <!-- endbuild -->
    <!-- build:css(.tmp) styles/main.css -->
    <link rel="stylesheet" href="styles/main.css">
    <!-- endbuild -->
  </head>
  <body ng-app="santaApp">
    <!--[if lte IE 8]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

    <!-- Add your site or application content here -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="#">Navbar</a>
      <ul class="navbar-nav">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Features</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Pricing</a>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" href="#">Disabled</a>
          </li>
        </ul>
    </nav>

    <div class="container">
      <div ng-view=""></div>
    </div>

    <div class="footer">
      <div class="container">
        <p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
      </div>
    </div>

    <!-- javascripts here -->
</body>
</html>

我正在使用yeoman-angular生成器,只是修改它以使用 bootsrap4 ui-bootstrap4 。另外,我还在使用 Angular 1.x 。那些导航条代码就在bootstrap4网站上。我只是复制并插入它。

此外,所有参考文件(即js,css)都已成功链接,我在浏览器上进行了检查。

任何人都知道发生了什么事情?我没想到,因为我刚刚开箱即用,除了上面提到的bootstrap之外没有其他任何修改。

更新

当我在导航栏上方盘旋时,我注意到整个导航栏都是可点击的,我认为标签正在填充整个导航栏..但我仍然不明白它为什么会填满整个导航栏。

更新

根据当前的答案,我当前版本的bootstrap肯定有问题。所以我做的是我测试了另一个版本:

版本:Bootstrap v4.0.0-beta(https://getbootstrap.com)    - 结果是确定

版本:Bootstrap v4.0.0-alpha.6(https://getbootstrap.com)    - 结果不行

基于以上结果,我将使用v4.0.0-beta。

2 个答案:

答案 0 :(得分:0)

ul#menu li {
  display:inline;
}
<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <!-- build:css(.) styles/vendor.css -->
    <!-- bower:css -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
    <!-- endbower -->
    <!-- endbuild -->
    <!-- build:css(.tmp) styles/main.css -->
    <link rel="stylesheet" href="styles/main.css">
    
    <!-- endbuild -->
  </head>
  <body ng-app="santaApp">
    <!--[if lte IE 8]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

    <!-- Add your site or application content here -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="#">Navbar</a>
      <ul id="menu" class="navbar-nav">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Features</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Pricing</a>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled" href="#">Disabled</a>
          </li>
        </ul>
    </nav>

    <div class="container">
      <div ng-view=""></div>
    </div>

    <div class="footer">
      <div class="container">
        <p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
      </div>
    </div>

    <!-- javascripts here -->
</body>
</html>

  

查看css,为了显示内联,您需要使用display:inline;

答案 1 :(得分:0)

&#13;
&#13;
.navbar-collapse.collapse {
  display: block!important;
}

.navbar-nav>li, .navbar-nav {
  float: left !important;
}

.navbar-nav.navbar-right:last-child {
  margin-right: -15px !important;
}

.navbar-right {
  float: right!important;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.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"/>

  <body ng-app="santaApp">
    <!--[if lte IE 8]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->

    <!-- Add your site or application content here -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">Navbar</a>
        </div>
        <ul class="nav navbar-nav">
            <li class="active"><a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a></li>
            <li><a class="nav-link" href="#">Features</a></li>
            <li><a class="nav-link" href="#">Pricing</a></li>
            <li><a class="nav-link disabled" href="#">Disabled</a></li>
        </ul>
      </div>
    </nav>

    <div class="container">
      <div ng-view=""></div>
    </div>

    <div class="footer">
      <div class="container">
        <p><span class="glyphicon glyphicon-heart"></span> from the Yeoman team</p>
      </div>
    </div>
    <!-- javascripts here -->
</body>
&#13;
&#13;
&#13;