在Bootstrap 4中创建响应式导航栏边栏“抽屉”吗?

在Bootstrap 4中创建响应式导航栏边栏“抽屉”吗?,第1张

在Bootstrap 4中创建响应式导航栏边栏“抽屉”吗?

侧边栏导航可能非常复杂。这就是Bootstrap没有“开箱即用”组件的原因。 补充工具栏有很多注意事项

  • 响应式-根据屏幕宽度设置不同的宽度,可见性或方向?
  • 多级-导航项是否具有子级?这个高度会受到怎样的影响?
  • 可切换-边栏可以通过按钮或“汉堡包”切换吗?
  • 推送与重叠-页面内容是隐藏在侧边栏的后面还是旁边?
  • 左侧还是右侧-页面内容左侧还是右侧的侧边栏是?
  • 固定或固定-侧边栏在页面滚动上的位置如何?
  • 动画样式-向左/向右/向上/向下滑动?是否折叠?

在这种“侧边栏”情况下…而不是

col-auto
在右列中使用
col
。这样,当折叠菜单时它将填充宽度

<div >  <div >    <div  id="collapseExample">       ..    </div>    <div >      <div >        <div >          <button  data-toggle="collapse" href="#collapseExample" role="button"> Menu          </button></div>        <div >..        </div>      </div>    </div>  </div></div>

为了使动画更加平滑,必须覆盖Bootstrap的折叠过渡,该过渡通常在高度上起作用

编辑:

根据赏金要求,我用另外2个示例更新了侧边栏

最低版本

该版本更接近示例,并且具有相同的幻灯片左/右“抽屉”动画。

body {    height: 100vh;    overflow-x: hidden;    padding-top: 56px;}.vh-100 {    min-height: 100vh;}.sidebar.collapse.show,.sidebar.collapse.show + .col {    transition: .18s ease;    transform: translate(0,0,0);    left: 0;}.sidebar.collapse,.sidebar.collapsing,.sidebar.collapsing + .col {    transition: .18s ease;    transform: translate(-25%,0,0);    z-index: 1050;    left: -25%;}

完整版本非常 接近:

此侧边栏具有:

  • 固定宽度
  • 自动关闭在小屏幕上在更广泛的屏幕打开
  • 可以任意宽度打开/关闭
  • 反应灵敏- 在较小宽度上 成为 固定覆盖

完整版确实需要更多CSS,但是其中一些是可选的…

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/><link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><style>body {   height: 100vh;   overflow-x: hidden;   padding-top: 55px;}.w-sidebar {    width: 200px;    max-width: 200px;}.row.collapse {    margin-left: -200px;    left: 0;    transition: margin-left .15s linear;}.row.collapse.show {    margin-left: 0 !important;}.row.collapsing {    margin-left: -200px;    left: -0.05%;    transition: all .15s linear;}.vh-100 {    min-height: 100vh;}@media (max-width:768px) {    .row.collapse,    .row.collapsing {        margin-left: 0 !important;        left: 0 !important;        overflow: visible;    }    .row > .sidebar.collapse {        display: flex !important;        margin-left: -100% !important;        transition: all .3s linear;        position: fixed;        z-index: 1050;        max-width: 0;        min-width: 0;        flex-basis: auto;    }    .row > .sidebar.collapse.show {        margin-left: 0 !important;        width: 100%;        max-width: 100%;        min-width: initial;    }    .row > .sidebar.collapsing {        display: flex !important;        margin-left: -10% !important;        transition: all .2s linear !important;        position: fixed;        z-index: 1050;        min-width: initial;    }}</style><div >    <div >        <div > <!-- spacer col -->        </div>        <div > <!-- toggler --> <a data-toggle="collapse" href="#" data-target=".collapse" role="button" >     <i ></i> </a>        </div>    </div></div><div >    <div >        <div > <!-- fixed sidebar --> <div >     <ul >         <li >  <a  href="#">link</a>         </li>         <li >  <a  href="#">link</a>         </li>     </ul> </div>        </div>        <div > <h3>Content..</h3> <p >Try this is full-page view to see the animation on larger screens!</p> <p>Sriracha biodiesel taxidermy organic post-ironic, Intelligentsia salvia mustache 90's pre editing brunch. Butcher polaroid VHS art party, hashtag Brooklyn deep v PBR narwhal sustainable mixtape swag wolf squid tote bag. Tote bag cronut semiotics, raw denim deep v taxidermy messenger bag. Tofu YOLO Etsy, direct trade ethical Odd Future jean shorts paleo. Forage Shoreditch tousled aesthetic irony, street art organic Bushwick artisan cliche semiotics ugh synth chillwave meditation. Shabby chic lomo plaid vinyl chambray Vice. Vice sustainable cardigan, Williamsburg master cleanse hella DIY 90's blog. Ethical Kickstarter PBR asymmetrical lo-fi. Dreamcatcher street art Carles, stumptown gluten-free Kickstarter artisan Wes Anderson wolf pug. Godard sustainable you probably haven't heard of them, vegan farm-to-table!</p>        </div>    </div></div><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5620934.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存