bootstrap不在laravel 5.6中工作

时间:2018-03-26 08:53:38

标签: twitter-bootstrap laravel

我尝试在我的laravel版本5.6项目中添加导航栏,但它不添加样式,也不添加JS

image

我的代码:

<nav class="navbar navbar-inverse ">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <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="#">LSAPP</a>
      </div>
      <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
          <li><a href="/">Home</a></li>
          <li><a href="/about">About</a></li>
          <li><a href="/services">services</a></li>
        </ul>
      </div><!--/.nav-collapse -->
    </div>
  </nav>

1 个答案:

答案 0 :(得分:7)

考虑到你有一个新的laravel应用程序,你可以添加在头上

<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">

并在你身体的尽头

<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>

使用Laravel css和javascript样板。

请记住,Laravel 5.6使用Bootstrap 4.0,因此您需要使用其语法:

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">LSAPP</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav">
    <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="/about">About</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/services">Services</a>
      </li>
    </ul>
  </div>
</nav>

检查组件文档here

另外还要记住,默认的Laravel资产比JQuery和Bootstrap更多。