gpt4 book ai didi

sidebar - offcanvas-sidebar bootstrap 4 粘性侧边栏

转载 作者:行者123 更新时间:2023-12-02 16:09:10 27 4
gpt4 key购买 nike

嗨,我最近使用 bootstrap 4 offcanvas 模板来构建我的网站

http://v4-alpha.getbootstrap.com/examples/offcanvas/#

现在我想让我的侧边栏跟随用户滚动,但 bootstrap 删除了 Affix 类并建议使用 css 位置粘性。我尝试这样做并定位侧边栏,但它搞乱了布局。定位 .nav 也不起作用

HTML

<div class="container-fluid header navbar-fixed-top">        
<div class="row">
<div class="hidden-md-up col-xs-2">
<button type="button" class="btn btn-secondary" data-toggle="offcanvas"><i class="fa fa-bars"></i></button>
</div>

<div class="col-md-12 col-sm-8 col-xs-8">
<img src="images/logo.gif" class="img-fluid center-block" alt="emblem">
</div>
</div>
</div><!-- /HEADER -->

<div class="container-fluid">
<div class="row row-offcanvas row-offcanvas-left">

<div class="col-md-2 col-sm-2 col-xs-4 sidebar-offcanvas" id="sidebar">
<ul class="nav nav-stacked">
<li class="nav-item">
<a class="nav-link" href="#home">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#area">Locations</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#deals">Deals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact Us</a>
</li>
</ul>
</div><!-- /Navigation -->


<section id="home">
<div class="row">

<div class="col-md-6 col-md-offset-5 col-sm-8 col-sm-offset-2 col-xs-10 col-xs-offset-1">
<img src="images/mazda2.gif" alt="Mazda2" class="img-fluid center-block">
</div>

<div class="col-md-6 col-md-offset-5 col-xs-12 text-xs-center">
<h3>Perth, Western Australia</h3>
</div>

</div>
</section><!-- HOME -->

<section id="about">
<div class="about-me">
<h3>About Us</h3>

</div>
</section><!-- ABOUT -->

</div><!--ROW -->
</div><!-- CONTAINER-FLUID -->

CSS

 /*
* Style tweaks
* --------------------------------------------------
*/
html,
body {
overflow-x: hidden; /* Prevent scroll on narrow devices */
}
body {
padding-top: 7em;
position: relative;
}

/*
* Off Canvas
* --------------------------------------------------
*/
@media screen and (max-width: 767px) {
.row-offcanvas {
position: relative;
-webkit-transition: all .25s ease-out;
-o-transition: all .25s ease-out;
transition: all .25s ease-out;
}

.row-offcanvas-left {
left: 0;
}

.row-offcanvas-right {
right: 0;
}

.row-offcanvas-left
.sidebar-offcanvas {
left: -33%; /* 4 columns */
}

.row-offcanvas-right
.sidebar-offcanvas {
right: -33%; /* 4 columns */
}

.row-offcanvas-left.active {
left: 33%; /* 4 columns */
}

.row-offcanvas-right.active {
right: 33%; /* 4 columns */
}

.sidebar-offcanvas {
position: absolute;
top: 0;
width: 33%; /* 4 columns */

}
}

/*
* Custom Style
* --------------------------------------------------
*/

#sidebar {
background-color: white;
position:absolute;
height:100vh;
}

.header {
background-color: #232323;
}

.btn-secondary {
background-color: #232323;
border-color: #232323;
margin-top:0.3em;
}

/*
* HOME
*/

#home {
background-color: #434343;
height: 100vh;
width: 100vw;
}

这可能与我的侧边栏关闭 Canvas 和侧边栏位置有关。但是如果没有我的侧边栏绝对位置,我的部分内容就会被推下。我尝试删除它并使用 col-x-x 类,但没有成功:(

最佳答案

我认为你应该使用:

@media screen and (min-width: 768px) {
.sidebar-offcanvas .nav-stacked {
position: fixed;
top: 8em;
width: 33%;
}
}

了解有关位置:固定的更多信息,请访问:Affix is not working in Bootstrap 4 alpha

关于sidebar - offcanvas-sidebar bootstrap 4 粘性侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36886552/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com