Unable to float a twitter bootstrap navbar item right with either class=pull-right or float:right

前端 未结 6 435
礼貌的吻别
礼貌的吻别 2021-02-04 09:37

I am using Twitter bootstrap and Rails and I can\'t seem to float a navbar item to the right.

I tried using something like this:

  • 相关标签:
    6条回答
    • 2021-02-04 10:18
      <li><a href="#examples"><span class="glyphicon glyphicon-chevron-right" style="float:right;"></span> Examples</a></li>
      
      0 讨论(0)
    • 2021-02-04 10:19

      The code u have written is

       class="nav navbar-nav" col-12
      

      The above code can be replaced like this

      class="nav navbar-nav col-12" 
      

      and also at next insert

      class pull-right in your li button
      
      0 讨论(0)
    • 2021-02-04 10:19

      Try commenting out the line

      //...REMOVED

      0 讨论(0)
    • 2021-02-04 10:29

      have you tried being more specific with your CSS?

      .navbar ul.nav li.whoami {
          float:right;
      }
      

      Sometimes if the prior CSS (bootstrap in this case) is very specific, it requires the same level of specificity (or greater) to override it.

      Might be helpful to post a jsfiddle. Screenshots are difficult to debug ;)

      0 讨论(0)
    • 2021-02-04 10:30

      Got it.

      Getting it to work required filling the container nested in navbar-inner with more than one unordered list of nav elements. This jsfiddle showed me the way http://jsfiddle.net/N6vGZ/4/

      This code works:

      <div class="container span12">
        <div class="navbar navbar-fixed-top">
          <div class="navbar-inner">
            <div class="container">
              <%= link_to "Cases", root_path, :class=>"brand"%>
                <ul class="nav">
                <% if user_signed_in? %>
                    <li> <%= link_to "My Cases", cases_path %> </li> 
                    <li> <%= link_to 'Dash', dash_path %> </li> 
                  <% if current_user.has_role? :admin %>
                    <li> <%= link_to 'Admin', users_path, :id=>"Admin" %> </li>
                  <% end %>
                  <li> <%= link_to 'Logout', destroy_user_session_path, :method=>'delete', :id => "Logout" %> </li>
                </ul>
                 <ul class="nav pull-right"> <li> <%= link_to ("Logged in as: " + current_user.name), edit_user_registration_path , :id=>"Edit account"%> </li></ul>
                <% else %>
                  <ul class="nav">
                    <li> <%= link_to 'Login', new_user_session_path %> </li>
                    <li> <%= link_to 'Sign up', new_user_registration_path %> </li>
                  </ul>
                <% end %>
              </ul>
            </div>
          </div>
        </div>
      </div>
      
      0 讨论(0)
    • 2021-02-04 10:35

      Add new class = "row"

      what's happened ..in your code . when it is coming in mobile device then div is append on other div . this is simple solution .

      0 讨论(0)
    提交回复
    热议问题