【问题标题】:Rails 5 + Boptstrap 4: Navbar not working on mobileRails 5 + Bootstrap 4:导航栏无法在移动设备上运行
【发布时间】:2018-04-10 04:00:39
【问题描述】:

这是我的第一个 stackoverflow 问题..

我正在尝试在 Rails 5 上安装 Boostrap 4,我认为一切正常,但是当我从移动设备检查网站时,我注意到导航栏与“通常”大小相比非常小(但至少它是正确的崩溃)。 我关注了官方的"Bootstrap Ruby Gem"但是没有用。

这是当前网站的导航栏(它只是来自 boostrap 组件的基本导航栏): https://warm-peak-79199.herokuapp.com/

关注我的文件:

宝石文件:

gem 'bootstrap', '~> 4.0.0.beta2.1'

Application.scss:

// Custom bootstrap variables must be set or imported *before* bootstrap.
@import "bootstrap";

Application.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require_tree .

Application.erb.html:

<!DOCTYPE html>
  <html>
    <head>
      <title>FlickerFeed</title>
      <%= csrf_meta_tags %>

      <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    </head>

    <body>
      <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 dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Dropdown
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Something else here</a>
              </div>
            </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="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
          </form>
        </div>
      </nav>
    </body>
  </html>

谁能帮助我了解问题所在? 太感谢了! 石志

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap bootstrap-4


    【解决方案1】:

    您的网站缺少responsive meta tag。将此添加到 &lt;head&gt; 标签内的布局中:

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    【讨论】:

      猜你喜欢
      • 2015-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      相关资源
      最近更新 更多