简体   繁体   English

Bootstrap 4 Navbar在页面加载时折叠为移动(Laravel / laravel-mix)

[英]Bootstrap 4 Navbar Collapsed for Mobile on Page Load (Laravel/laravel-mix)

Well I'm not really sure to turn at this point because this makes absolutely no sense to me. 好吧,我现在不确定要转弯,因为这对我来说绝对没有意义。

I'm using the latest version of Laravel and Laravel Mix, which may or may not be related. 我正在使用最新版本的Laravel和Laravel Mix,它们可能相关也可能不相关。

I've updated Laravel to use the latest Bootstrap 4 Alpha with the following dependencies: 我已经更新Laravel以使用具有以下依赖项的最新Bootstrap 4 Alpha:

"axios": "^0.16.2",
"bootstrap": "^4.0.0-alpha.6",
"cross-env": "^5.0.1",
"jquery": "^3.1.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10",
"tether": "^1.4.0",
"popper.js": "^1.11.0"

Everything here is the correct versions. 这里的一切都是正确的版本。

I've updated my bootstrap.js to include the correct bootstrap module and the newly required modules: 我已经更新了bootstrap.js,使其包含正确的bootstrap模块和新要求的模块:

try {
    window.$ = window.jQuery = require('jquery');

    window.Tether = require('tether');
    window.Popper  = require('popper.js').default;
    require('bootstrap');
} catch (e) {}

I'v also corrected the SCSS path in app.scss: 我还纠正了app.scss中的SCSS路径:

@import "node_modules/bootstrap/scss/bootstrap"; 

Now the problem is that when I load the the app after running npm run dev the navbar is collapsed... as if it was on mobile, but I'm testing on a desktop. 现在的问题是,当我在运行npm run dev后加载应用程序时,导航栏会折叠起来……好像它在移动设备上一样,但是我正在台式机上进行测试。

Now it gets even weirder because if I include bootstrap.min.css from the Bootstrap CDN, then it works fine. 现在,它变得更奇怪了,因为如果我包含Bootstrap CDN中的bootstrap.min.css,那么它可以正常工作。

I don't want to do that though, but clearly I may end up having to because I have no idea what the problem is. 我虽然不想这样做,但显然我可能最终不得不这样做,因为我不知道问题出在哪里。

I've tried various things such as commenting out all my custom CSS, Javascript, reinstalling node_modules multiple times, etc. I'm lost at this point. 我已经尝试过各种方法,例如注释掉所有自定义CSS,Javascript,多次重新安装node_modules等。这时我迷路了。

edit: I've also tried using the default Bootstrap navbar when using my app.css file and it still doesn't work. 编辑:使用app.css文件时,我也尝试过使用默认的Bootstrap导航栏,但它仍然无法正常工作。 Again, works fine though if I use the CDN instead. 同样,如果我改用CDN,效果很好。

@Jake, my guess is you're getting bootstrap4.0.0-beta and trying to use markup and classes related to bootstrap4.0.0-alpha.6 . @Jake,我的猜测是您正在获取bootstrap4.0.0-beta并尝试使用与bootstrap4.0.0-alpha.6相关的标记和类。

If you uninstall bootstrap and run npm install bootstrap@4.0.0-alpha.6--save --save-exact , your code should work. 如果卸载引导程序并运行npm install bootstrap@4.0.0-alpha.6--save --save-exact ,则代码应该可以正常工作。

OR 要么

You can use this code for your navbar in you current project to see if it works correctly. 您可以在当前项目的导航栏中使用此代码,以查看其是否正常运行。

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Navbar</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <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="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM