【发布时间】:2017-08-07 03:58:13
【问题描述】:
我想在我的 asp.net MVC 应用程序中使用 boostrap 侧边栏,我在侧边栏的一侧使用了一个按钮(#menu-toggle),它将切换侧边栏。一切都很好,但是当我调整屏幕大小时,按钮消失了。我希望按钮在所有屏幕上都可见。通常我将左键放在按钮上,以便它与侧边栏的宽度匹配。
HTML
<div id="wrapper" class="toggled">
<div class="container-fluid">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">
</li>
@Html.Action("Reports", "Dashboard")
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div id="body">@RenderBody()</div>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
</div>
CSS
#menu-toggle {
z-index: 5;
position: absolute;
top: 500px;
left: 10px;
}
#menu-toggle.toggled {
z-index: 5;
position: absolute;
top: 500px;
left: 260px;
}
#wrapper {
padding-left: 0;
}
#wrapper.toggled {
padding-left: 250px;
}
#sidebar-wrapper {
position: fixed;
left: 250px;
z-index: 1000;
overflow-y: auto;
margin-left: -250px;
width: 0;
height: 100%;
background: #000;
}
#wrapper.toggled #sidebar-wrapper {
width: 250px;
}
#page-content-wrapper {
padding: 15px;
width: 100%;
}
#wrapper.toggled #page-content-wrapper {
position: absolute;
margin-right: -250px;
}
.sidebar-nav {
position: absolute;
top: 0;
margin: 0;
padding: 0;
width: 250px;
list-style: none;
}
.sidebar-nav li {
text-indent: 20px;
line-height: 40px;
}
.sidebar-nav li a {
display: block;
color: #999999;
text-decoration: none;
}
.sidebar-nav li a:hover {
background: rgba(255, 255, 255, 0.2);
color: #fff;
text-decoration: none;
}
.sidebar-nav li a:active,
.sidebar-nav li a:focus {
text-decoration: none;
}
.sidebar-nav>.sidebar-brand {
height: 65px;
font-size: 18px;
line-height: 60px;
}
.sidebar-nav>.sidebar-brand a {
color: #999999;
}
.sidebar-nav>.sidebar-brand a:hover {
background: none;
color: #fff;
}
@@media (min-width: 768px) {
#menu-toggle {
display:block;
z-index: 5;
position: absolute;
top: 500px;
left: 10px;
}
#menu-toggle.toggled {
z-index: 5;
position: absolute;
top: 500px;
left: 260px;
}
#wrapper {
padding-left: 250px;
}
#wrapper.toggled {
padding-left: 0px;
}
#sidebar-wrapper {
width: 250px;
}
#wrapper.toggled #sidebar-wrapper {
width: 0;
}
#page-content-wrapper {
padding: 20px;
}
#wrapper.toggled #page-content-wrapper {
position: relative;
margin-right: 0;
}
}
@@media (max-width: 768px) {
#menu-toggle {
display:block;
z-index: 5;
position: absolute;
top: 500px;
left: 10px;
}
#menu-toggle.toggled {
z-index: 5;
position: absolute;
top: 500px;
left: 260px;
}
#wrapper {
padding-left: 250px;
}
#wrapper.toggled {
padding-left: 0px;
}
#sidebar-wrapper {
width: 250px;
}
#wrapper.toggled #sidebar-wrapper {
width: 0;
}
#page-content-wrapper {
padding: 20px;
}
#wrapper.toggled #page-content-wrapper {
position: relative;
margin-right: 0;
}
}
jquery
$(document).on("click", "#menu-toggle", function (e) {
e.preventDefault();
$(this).toggleClass("toggled");
$("#wrapper").toggleClass("toggled");
});
【问题讨论】:
-
我在 HTML 中看不到
#menu-toggle,如果可能,请创建有效的 sn-p。 -
是的,添加您的工作示例链接
-
我正在用 asp.net mvc 开发。问题是屏幕调整大小后#menu-toggle 按钮消失..请帮助我参考以下链接bootply.com/dragan/3AZB0lGFyt
-
嗯,你的 css 和 bootply 的不一样,肯定是你的 css,试着像你提供的 bootply 一样构建一个,然后在这里链接
标签: html css asp.net-mvc twitter-bootstrap media-queries