添加时:
<%= link_to("Lessons",
{:controller => 'welcome',
:action => 'lessons'
}) %>
它在我的侧边栏上创建了一个新行。该链接应位于相同行,作为地球图标(地球图标位于正确位置)。其他链接看起来是正确的,因为我没有添加红宝石链接,以显示它们看起来没有红宝石链接。
参考导航栏: http://blog.codeply.com/2016/05/18/bootstrap-sidebar-responsive-examples/
我正在使用页面底部的固定宽度响应侧边栏。
HTML模板:
<!DOCTYPE html>
<html>
<head>
<title>Workspace</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top navbar-custom">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Kids Typing Club</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class=""><a href="#"></a></li>
<li><a href="#about"></a></li>
<li><a href="#contact"></a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.navbar -->
<div class="row-offcanvas row-offcanvas-left">
<div id="sidebar" class="sidebar-offcanvas">
<div class="col-md-12">
<h3></h3>
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#">Home</a></li>
<li><a><i class="fa fa-globe fa-lg"></i>
<%= link_to("Lessons",
{:controller => 'welcome',
:action => 'lessons'
}) %>
</a></li>
<li><a><i class="fa fa-user fa-lg"></i>
Profile
</a></li>
<li><a><i class="fa fa-users fa-lg"></i>
Users
</a></li>
<li><a><i class="fa fa-envelope fa-lg"></i>
Contact
</a></li>
<li><a><i class="fa fa-question-circle fa-lg"></i>
Help
</a></li>
</ul>
</div>
</div>
<div id="main">
<div class="col-md-12">
<p class="visible-xs">
<button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"><i class="glyphicon glyphicon-chevron-left"></i></button>
</p>
<h2>Fixed + Fluid Bootstrap Template with Off-canvas Sidebar</h2>
<div class="row">
<div class="col-md-12"><div class="well"><p>Shrink the browser width to make the sidebar collapse off canvase.</p></div></div>
</div>
<div class="row">
<div class="col-md-4"><div class="well"><p>4 cols</p></div></div>
<div class="col-md-4"><div class="well"><p>4 cols</p></div></div>
<div class="col-md-4"><div class="well"><p>4 cols</p></div></div>
</div>
<div class="row">
<div class="col-lg-6 col-sm-6"><div class="well"><p>6 cols, 6 small cols</p></div></div>
<div class="col-lg-6 col-sm-6"><div class="well"><p>6 cols, 6 small cols</p></div></div>
</div>
<div class="row">
<div class="col-lg-4 col-sm-6"><div class="well">4 cols, 6 small cols</div></div>
<div class="col-lg-4 col-sm-6"><div class="well">4 cols, 6 small cols</div></div>
<div class="col-lg-4 col-sm-12"><div class="well">4 cols, 12 small cols</div></div>
</div>
</div>
</div>
</div><!--/row-offcanvas -->
<%= yield %>
</body>
</html>
CSS文件:
// Place all the styles related to the Welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
//navbar css below
body,html,.row-offcanvas {
height:100%;
}
body {
padding-top: 50px;
}
#sidebar {
width: inherit;
min-width: 220px;
max-width: 220px;
background-color:#f5f5f5;
float: left;
height:100%;
position:relative;
overflow-y:auto;
overflow-x:hidden;
}
#main {
height:100%;
overflow:auto;
}
/*
* off Canvas sidebar
* --------------------------------------------------
*/
@media screen and (max-width: 768px) {
.row-offcanvas {
position: relative;
-webkit-transition: all 0.25s ease-out;
-moz-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
width:calc(100% + 220px);
}
.row-offcanvas-left
{
left: -220px;
}
.row-offcanvas-left.active {
left: 0;
}
.sidebar-offcanvas {
position: absolute;
top: 0;
}
}
//navbar sidebar css ends ^
//self-created CSS:
.navbar-brand{
color: white !important;
}
.navbar-custom{
background-color: #5BC0DE !important;
background: #5BC0DE !important;
}
#sidebar .active a{
background-color: #5BC0DE !important;
}
Javascript文件:
$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
});
输出:
答案 0 :(得分:1)
这应该可以解决你的问题
<li><%= link_to({:controller => 'welcome',
:action => 'lessons'
}) do %>
<i class="fa fa-globe fa-lg"></i> Lessons
<% end %>
</li>
答案 1 :(得分:-1)
谢谢@Fabrizio Bertoglio。使用他提供的信息我添加了这个css:
.menuitems > a:visited {
color: #337AB7 !important;
}
.active {
background-color: white;
}
.navbar-brand {
color: white !important;
}
我将menuitems作为一个类添加到每个链接。这允许我的导航栏品牌类规则不被a:覆盖(因为它适用于所有这些)。如果不将规则应用于特定菜单项,我的导航字体颜色将不会更改为所需的颜色。
链接对齐由@Fabrizio Bertoglio解决:
<li><%= link_to({:controller => 'welcome',
:action => 'lessons'
}) do %>
<i class="fa fa-globe fa-lg"></i> Lessons
<% end %>
</li>