如果您希望侧边栏总是出现在左侧,并且不想打开或关闭它,那么可以只使用引导,而不需要编写自定义的CSS。
为头部使用引导导航栏,并删除你为头部编写的任何额外的CSS,否则它将覆盖引导导航栏。
不使用
fixed-sidebar
类,而不是根据引导模式重新构造模板,您需要执行以下操作,并且您也不需要任何自定义的CSS:
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</header>
<div class="container-fluid">
<div class="row">
<!--Sidebar-->
<div class="col-md-3 col-xl-2">
<a class="logo" href="/">
<div class="img-wrap">
<img width="150" src="/assets/logo-white-cad55691e551f40916535bcbe93173c0d76adc0bf6db8d15de937e475874f76a.png" />
</div>
</a>
<div class="mCustomScrollbar ps ps--theme_default" data-mcs-theme="dark">
<ul class="left-menu">
<li>
<a href="/">
<svg xmlns="http://www.w3.org/2000/svg" class="left-menu-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg>
<span class="left-menu-title">Dashboard</span>
</a> </li>
<li>
<a href="/questions">
<svg xmlns="http://www.w3.org/2000/svg" class="left-menu-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-help-circle"><circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12" y2="17"></line></svg>
<span class="left-menu-title">Questions</span>
</a> </li>
<li>
<a href="/categories">
<svg xmlns="http://www.w3.org/2000/svg" class="left-menu-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-list"><line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3" y2="6"></line><line x1="3" y1="12" x2="3" y2="12"></line><line x1="3" y1="18" x2="3" y2="18"></line></svg>
<span class="left-menu-title">Categories</span>
</a> </li>
<li>
<a href="/tournaments">
<svg xmlns="http://www.w3.org/2000/svg" class="left-menu-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-grid"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
<span class="left-menu-title">Tournaments</span>
</a> </li>
<li>
<a href="/users">
<svg xmlns="http://www.w3.org/2000/svg" class="left-menu-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="9" cy="7" r="4"></circle><path d="M23 21v-2a4 4 0 0 0-3-3.87"></path><path d="M16 3.13a4 4 0 0 1 0 7.75"></path></svg>
<span class="left-menu-title">Users</span>
</a> </li>
</ul>
</div>
</div>
<!--Main content-->
<div class="col-md-9 col-xl-10">
<div class="row">
<div class="col-lg-3">
<p>Anything in this content area is being squished under the sidebar when being scaled down</p></div>
</div>
<div class="col-lg-3">
<div data-react-class="StatCard" data-react-props="{"title":"Questions","data":1}"></div>
</div>
<div class="col-lg-3">
<div data-react-class="StatCard" data-react-props="{"title":"Categories","data":2}"></div>
</div>
<div class="col-lg-3">
<div data-react-class="StatCard" data-react-props="{"title":"Tournaments","data":1}"></div>
</div>
</div>
</div>
</div>
</div>
</body>
引导程序本身提供了很多功能,您只需遵循文档,就可以获得所需的一切。始终尝试使用框架的功能,而不是定义自定义的CSS或覆盖现有的CSS。只有当框架提供的任何组件都无法实现时,才能编写自定义的CSS。
另外,如果您想隐藏小设备的固定侧边栏,并在下拉列表中显示它们,那么您可以对小设备使用引导程序的折叠功能。