我目前正在试验Twitter Bootstrap,但我的固定侧边栏有问题。 将鼠标悬停在左侧的菜单项上时,您可以看到菜单不会停止内容区域的开始位置。我真的不知道如何正确解释它,所以我希望这很清楚。
我想知道是否有解决方案。
答案 0 :(得分:1)
将CSS
替换为
#sidebar .nav {
width: 95%;
position: fixed;
}
以强>
#sidebar .nav {
width: 10%; // change width as your choice
position: fixed;
}
您可以选择侧边栏95%的浏览器窗口宽度。
答案 1 :(得分:1)
<强> DEMO 强>
HTML
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand"><a href="#">Fixed Menu</a>
</li>
<li><a href="#">Menu 1</a>
</li>
<li><a href="#">Menu 2</a>
</li>
<li><a href="#">Menu 3</a>
</li>
<li><a href="#">Link 1</a>
</li>
<li><a href="#">Link 2</a>
</li>
<li><a href="#">Link 3</a>
</li>
<li><a href="#">Link 4</a>
</li>
</ul>
</div>
<!-- Page content -->
<div id="page-content-wrapper">
<div class="content-header">
<h1>
<a id="menu-toggle" href="#" class="btn btn-default btn-success"><i class="icon-reorder"></i></a>
Sidebar Fixed
</h1>
</div>
<!-- Keep all page content within the page-content inset div! -->
<div class="page-content inset">
<div class="row">
<div class="col-md-12">
<p class="lead">Resize window to see effect.</p>
</div>
</div>
</div>
</div>
</div>
CSS
#wrapper {
padding-left: 250px;
transition: all 0.4s ease 0s;
}
#sidebar-wrapper {
margin-left: -250px;
left: 250px;
width: 250px;
background: #000;
position: fixed;
height: 100%;
overflow-y: auto;
z-index: 1000;
transition: all 0.4s ease 0s;
}
#page-content-wrapper {
width: 100%;
}
.sidebar-nav {
position: absolute;
top: 0;
width: 250px;
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-nav li {
line-height: 40px;
text-indent: 20px;
}
.sidebar-nav li a {
color: #999999;
display: block;
text-decoration: none;
}
.sidebar-nav li a:hover {
color: #fff;
background: rgba(255,255,255,0.2);
text-decoration: none;
}
.sidebar-nav li a:active,
.sidebar-nav li a:focus {
text-decoration: none;
}
.sidebar-nav > .sidebar-brand {
height: 65px;
line-height: 60px;
font-size: 18px;
}
.sidebar-nav > .sidebar-brand a {
color: #999999;
}
.sidebar-nav > .sidebar-brand a:hover {
color: #fff;
background: none;
}
.content-header {
height: 65px;
line-height: 65px;
}
.content-header h1 {
margin: 0;
margin-left: 20px;
line-height: 65px;
display: inline-block;
}
#menu-toggle {
display: none;
}
.inset {
padding: 20px;
}
@media (max-width:767px) {
#wrapper {
padding-left: 0;
}
#sidebar-wrapper {
left: 0;
}
#wrapper.active {
position: relative;
left: 250px;
}
#wrapper.active #sidebar-wrapper {
left: 250px;
width: 250px;
transition: all 0.4s ease 0s;
}
#menu-toggle {
display: inline-block;
}
.inset {
padding: 15px;
}
}
JS
<!-- Custom JavaScript for the Menu Toggle -->
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("active");
});