Bootstrap 3 navbar links display vertical when sho

2019-03-01 12:09发布

问题:

Following Michael Hartl's ruby on rails tutorial and after importing bootstrap into a custom.css.scss file the links display as a block (vertical) when they should really be horizontal causing the navbar to be really thick as shown below. So the question is what did I do wrong and how can I make the navigation horizontal using boostrap?

Here's my application.html.erb layout

<!DOCTYPE html>
<html>
    <head>
      <title><%= full_title(yield(:title)) %></title>
      <%= stylesheet_link_tag  "application", media: "all", "data-turbolinks-track" => true %>
      <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
      <%= csrf_meta_tags %>
      <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    </head>
    <body>
        <header class="navbar navbar-fixed-top navbar-inverse">
            <div class="navbar-inner">
                <div class="container">
                    <%= link_to "Dog Park", root_path, id: "logo" %>
                    <nav>
                        <ul class="nav pull-right">
                            <li><%= link_to "Home", root_path %></li>
                            <li><%= link_to "About", about_path %></li>
                            <li><%= link_to "Help", help_path %></li>
                            <li><%= link_to "Play Time", '#' %></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        <div class="container">
            <%= yield %>
        </div>
    </body>
</html>

here's my Gemfile

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.2'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
  gem 'guard-rspec', '2.5.0'
  gem 'spork-rails', '4.0.0'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'growl', '1.0.3'
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem "bootstrap-sass", "~> 3.0.3.0"

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

回答1:

(I don't have enough rep to comment on Mlennie's answer, so this needs to be a separate answer)

As Mlennie says, "adding a navbar-nav class finally worked."

What this means is to change:

<ul class="nav pull-right">

To:

<ul class="nav pull-right navbar-nav">


回答2:

Adding a navbar-nav class finally worked.