我试图找出问题的答案,但我似乎无法找到答案。如果有任何机会确实有解决方案,那么,对不起,我的坏!
我似乎遇到了Bootstrap默认导航栏的问题:下拉菜单:.navbar-right
由于某种原因向左浮动。你可以查看here。
我正在使用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>
您可以在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);
}
奇怪的是,当我登录时,下拉菜单会回到正确的位置...... 在检查代码时,我几乎找到了一个修复,删除左浮动到这一部分:
@media (min-width: 768px)
custom.self-839…ss?body=1:5864
.navbar-nav {
float: left;
margin: 0;
}
但很明显,当我这样做时,它会与导航栏的其余部分混淆。 任何人都可以帮助我?在此先感谢!!
答案 0 :(得分:1)
尝试使用引导网格系统,它可以让您轻松定位菜单项:
* Bootstrap列语法 - &gt; class="col-[screen size]-[number of columns]"
屏幕尺寸---&gt; xs(超小),sm(小),md(中),lg(大)
列数---&gt;最多12个
*使用class="col-md-offset-[number of columns]"
向右移动列。
这些类将列的左边距增加一定数量的列。
例如,class="col-md-offset-4"
会将列移到四列上。
*使用以下命令轻松更改内置网格列的顺序:
class ="col-md-push-[number of columns]"
和class ="col-md-pull-[number of columns]"
This video is showing the basic concept - 这家伙有很多视频......
编辑:这就是我解决了与其他按钮连接的下拉按钮的问题...
<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>
答案 1 :(得分:1)
这只是一种预感,但我认为值得尝试......我想知道改变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>
答案 2 :(得分:1)
首先!谢谢大家帮助! @Gal,你的答案实际上让我朝着正确的方向前进,我终于找到了我的错误! (是的,错误始终位于键盘和椅子之间!哈哈哈!)
好吧,将Gal的代码应用到我的导航中。我发现问题来自于有问题的下拉列表被认为包含在:
中<ul class="nav navbar-nav">
那时我认为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 %>
我只需将</ul>
标记切换为<% end %>
,就像这样:
<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 %>
它就像一个魅力!
再次感谢大家!!!