简体   繁体   English

bootstrap nav-bar-right left left

[英]bootstrap nav-bar-right floating left

I tried to look out for an answer for my problem but I can't seem to find one. 我试图寻找我的问题的答案,但我似乎找不到一个。 If by any chance there actually is a solution out there, then, I'm sorry, my bad! 如果有任何机会确实有解决方案,那么,对不起,我的坏!

I seem to be encountering a problem with Bootstrap's default nav bar: The dropdown menu: .navbar-right is floating left for some reason. 我似乎遇到了Bootstrap默认导航栏的问题:下拉菜单: .navbar-right由于某种原因向左浮动。 You can check it out here . 你可以在这里查看 I'm working on rails 5 and the code for my nav currently looks like: 我正在使用rails 5,我的导航代码目前看起来像:

    <nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <%= link_to "Prodemex", root_path, class: "navbar-brand", id: "logo" %>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><%= link_to "Articulos", articles_path %></li>
        <li><%= link_to "Usuarios", users_path %></li>
        <% if logged_in? %>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Actions <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><%= link_to "Nuevo articulo", new_article_path %></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
      <% end %>
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <% if logged_in? %>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Mi cuenta<%= " - Admin " if current_user.admin? %><span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><%= link_to "Modificar mis datos", edit_user_path(current_user) %></li>
                <li><%= link_to "Ver mi perfil", user_path(current_user) %></li>
                <li><a href="#">Something else here</a></li>
                <li role="separator" class="divider"></li>
                <li><%= link_to 'Cerrar sesión', logout_path, method: :delete %></li>
              </ul>
            </li>
        </ul>
        <% else %>
        <ul class="navbar-right nav navbar-nav">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Mi cuenta <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><%= link_to 'Iniciar sesión', login_path %></li>
              <li><%= link_to 'Registrarse', signup_path %></li>
            </ul>
          </li>
        </ul>
        <% end %>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

You can retrieve more of the code on github I have a custom CSS with all that and already tried to delete all portions related with navbar but it did nothing... 你可以在github上检索更多的代码我有一个自定义的CSS,并且已经尝试删除与navbar相关的所有部分,但它没有做任何事......

$navbar-default-bg: #3498DB;

@import "bootstrap-sprockets";
@import "bootstrap";

.gen {
  padding: 0 2%;
}

.col-xs-8 {
  float: none;
}

a {
  text-decoration: none;
}

body {
  font-weight: 200;
}

#logo {
  float: left;
  font-size: 1.7em;
  color: #fff;
  text-transform: uppercase;
  font-weight: 200;
}

#logo:hover {
  text-decoration: none;
  color: #5e82a6;
}

.navbar {
  border-radius: 0;
  margin: 0;
}

.center {
  text-align: center;
}

#home {
  background: linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35)), image-url('cover_page.jpg');
  background-size: cover;
  background-attachment: fixed;
  height: 100vh;
}

.jumbotron {
  padding: 15.5% 20%;
  background-color: transparent;

  }

.jumbotron h1,h3 {
  color: #fff;
  font-weight: 200;
  margin-bottom: 10px;
}

.btn-xlg {
  font-size: 1.2em;
  font-weight: 200;
  background-color: #3498DB;
  border: 1px solid #3498DB;
  margin: 0;
  display: inline-block;
  letter-spacing: 1px;
}

.btn-xlge {
  font-size: 1.2em;
  font-weight: 200;
  color: #000;
  background-color: none;
  border: 1px solid #000;
  margin-left: 10px;
  display: inline-block;
}

.btn-xlge:hover,
          active {
  background-color: #337ab7;
  color: #fff;
  border: 1px solid #337ab7;
}

.footer {
  background-color: #3498DB;
  color: #fff;
  letter-spacing: 1px;
  padding: 10px;
}

footer ul {
  list-style:none;
  margin-top: 10px;
}

.footer a {
  color: #fff;
}

.footer a:hover,
.footer a:active {
  color: #ccc;
  text-decoration: none;
}

.article-actions {
  border-top: 1px solid #eaeaea;
  padding-top: 15px;
  margin-top: 10px;
}

.descrition {
  margin-top: 0;
}

.article-title {
  font-size: 1.5em;
}

.article-title a {
  text-decoration: none;
}

.article-body {
  border-top: 1px solid #eaeaea;
  padding-top: 15px;
  padding-bottom: 15px;
}

.article-meta-details {
  margin-top: 5px;
  margin-bottom: 0;
  font-size: 1em;
}

.article-meta-details a {
  text-decoration:none;
}

.well-lg {
  padding-bottom: 10px;
}

.listing {
  list-style: none;
  padding-left: 0;
}

.insideuser {
  padding-left: 50px;
  float: left;
}

.author {
  font-weight: 400;
  color: #3498DB;
}

.authorpage {
  margin-top: 10px;
  padding: 10px 0;
}

.pop {
  margin-top: 15px;
  -webkit-box-shadow: 4px 1px 10px 0px rgba(50, 50, 50, 0.27);
  -moz-box-shadow:    4px 1px 10px 0px rgba(50, 50, 50, 0.27);
  box-shadow:         4px 1px 10px 0px rgba(50, 50, 50, 0.27);
}

And the weird thing is that when I log in, the dropdown goes back to the right where it is supposed to be... When inspecting the code, I almost found a fix, deleting the left float to this portion: 奇怪的是,当我登录时,下拉列表会回到正确的位置......当检查代码时,我几乎找到了一个修复程序,将左侧浮动删除到此部分:

@media (min-width: 768px)
custom.self-839…ss?body=1:5864
.navbar-nav {
    float: left;
    margin: 0;
}

But obviously when I do that it messes up with the rest of the navbar. 但显然当我这样做时,它会与导航栏的其余部分混淆。 Any body can help me? 任何人都可以帮助我? Thanks in advance!! 提前致谢!!

try to use the bootstrap grid system it will make it easy for you to position your menu items : 尝试使用引导网格系统,它将使您轻松定位菜单项:


*Bootstrap column syntax -- > class="col-[screen size]-[number of columns]" * Bootstrap列语法 - > class="col-[screen size]-[number of columns]"

screen sizes ---> xs (extra small) , sm (small) , md (medium) , lg (large) 屏幕尺寸---> xs(超小),sm(小),md(中),lg(大)

number of columns ---> goes up to 12 列数--->最多12个


*Move columns to the right using class="col-md-offset-[number of columns]" . *使用class="col-md-offset-[number of columns]"将列移到右侧。

These classes increase the left margin of a column by a set number of columns. 这些类将列的左边距增加一定数量的列。

For example, class="col-md-offset-4" moves a column over four columns. 例如, class="col-md-offset-4"将列移动到四列。


*Easily change the order of our built-in grid columns with : *使用以下命令轻松更改内置网格列的顺序:

class ="col-md-push-[number of columns]" and class ="col-md-pull-[number of columns]" class ="col-md-push-[number of columns]"class ="col-md-pull-[number of columns]"


Bootstrap Grid System Bootstrap网格系统

This video is showing the basic concept - This guy has a whole searies of videos ... 这个视频展示了基本概念 - 这个家伙有很多视频......


Edited: This is how I solved the problem of a dropdown button that was joined with the rest of the buttons ... 编辑:这就是我解决了与其他按钮连接的下拉按钮的问题...

<ul class="nav nav-pills col-lg-offset-11 col-md-offset-11 col-sm-offset-11">
 <li id="btnDrpDwn" role="presentation" class="dropdown"><a data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle">menu<span class="caret"></span></a>
  <ul class="dropdown-menu">
    <li role="presentation"><a href="/profile">Item 1</a></li>
    <li role="presentation"><a href="#">Item 2</a></li>
    <li role="separator" class="divider"></li>
    <li role="presentation"><a href="/logout">Item 3</a></li>
  </ul>
 </li></ul>

This is just a hunch, but I thought it was worth trying...I wonder if changing where you have your if/else statement will help? 这只是一种预感,但我认为值得尝试...我想知道改变if / else语句的位置会有所帮助吗?

<ul class="nav navbar-nav navbar-right">
  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Mi cuenta<%= " - Admin " if current_user.admin? %><span class="caret"></span></a>
     <% if logged_in? %>
       <ul class="dropdown-menu">
         <li><%= link_to "Modificar mis datos", edit_user_path(current_user) %></li>
         <li><%= link_to "Ver mi perfil", user_path(current_user) %></li>
         <li><a href="#">Something else here</a></li>
         <li role="separator" class="divider"></li>
         <li><%= link_to 'Cerrar sesión', logout_path, method: :delete %></li>
       </ul>
     <% else %>
       <ul class="dropdown-menu">
         <li><%= link_to 'Iniciar sesión', login_path %></li>
         <li><%= link_to 'Registrarse', signup_path %></li>
       </ul>
     <% end %>
  </li>
</ul>

First off! 首先! Thanks guys for your help! 谢谢大家帮助! @Gal, your answer actually put me in the right direction and I finally found where my mistake was! @Gal,你的答案实际上让我朝着正确的方向前进,我终于找到了我的错误! (Yes, the errors is always located between the keyboard and the chair! hahhahaha!) (是的,错误始终位于键盘和椅子之间!哈哈哈!)

OK so by implementing Gal's code into my nav. 好吧,通过在我的导航中实现Gal的代码。 I found out that the problem was coming from the fact that the problematic dropdown was considered as included in the: 我发现问题来自于有问题的下拉列表被认为包括在:

<ul class="nav navbar-nav">

And that's when I figure that the UL wasn't closing properly! 那就是我认为UL没有正常关闭的时候! This portion was the problematic one: 这部分是有问题的:

<ul class="nav navbar-nav">
        <li><%= link_to "Articulos", articles_path %></li>
        <li><%= link_to "Usuarios", users_path %></li>
        <% if logged_in? %>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Actions <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><%= link_to "Nuevo articulo", new_article_path %></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
      <% end %>

I just switch the </ul> tag with the <% end %> one like this: 我只是用<% end %>切换</ul>标签,如下所示:

<ul class="nav navbar-nav">
        <li><%= link_to "Articulos", articles_path %></li>
        <li><%= link_to "Usuarios", users_path %></li>
        <% if logged_in? %>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Actions <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><%= link_to "Nuevo articulo", new_article_path %></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
      <% end %>

and it works like a charm! 它就像一个魅力!

Thanks again everyone!!! 再次感谢大家!

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

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