当屏幕宽度小于768像素时,Boostrap dashboard example完全隐藏侧边栏导航(不折叠或堆叠)。您如何通过这样的设置支持移动设备?
答案 0 :(得分:10)
Bootstrap 4
Create a responsive navbar sidebar "drawer" in Bootstrap 4?
Bootstrap 3
另一个选择是将仪表板和" off-canvas"侧边栏模板。这种布局允许侧栏在较小的宽度上切换/关闭屏幕......
@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;
}
.row-offcanvas-left
.sidebar-offcanvas {
left: -33%;
}
.row-offcanvas-left.active {
left: 33%;
}
.sidebar-offcanvas {
position: absolute;
top: 0;
width: 33%;
margin-left: 10px;
}
}
/* Sidebar navigation */
.nav-sidebar {
background-color: #f5f5f5;
margin-right: -15px;
margin-bottom: 20px;
margin-left: -15px;
}
.nav-sidebar > li > a {
padding-right: 20px;
padding-left: 20px;
}
.nav-sidebar > .active > a {
color: #fff;
background-color: #428bca;
}
答案 1 :(得分:4)
“大于”移动视图的侧边栏的CSS在以下位置指定:
@media (min-width: 768px)
.sidebar {
position: fixed;
top: 51px;
bottom: 0;
left: 0;
z-index: 1000;
display: block;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
background-color: #f5f5f5;
border-right: 1px solid #eee;
}
之后它将恢复为默认值display:none
.sidebar {
display: none;
}
您需要更改其默认CSS,或添加新的media query,例如
@media (max-width: 768px)
为了专门针对较小的设备。您希望应用的样式类型取决于您所追求的内容。