我正在进行模拟,我想要一个全屏旋转木马,导航栏链接位于图像顶部。目前,导航栏是清晰的,当我向下滚动图像/滑块时,它是全屏。如何在初始加载时将导航栏放在旋转木马的顶部?我也在使用BS4 alpha。
目前: current position of nav bar on load
通缉: wanted position of navbar on load
代码:
html,body {
height:100vh;
}
.carousel, .item, .active {
height:100vh;
}
.carousel {
top: 0;
}
.carousel-inner {
height:100vh;
}
.carousel-inner img {
margin: auto;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" ></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" ></script>
<!--nav bar -->
<nav class="navbar sticky-top navbar-toggleable-md navbar-light">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Cold Denver</a>
<!-- all the links inside mobile menu -->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- left side nav bar -->
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Store</a>
</li>
</ul>
</div>
</nav>
<!-- end nav -->
<div id="fullCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="img-fluid" src="http://via.placeholder.com/1920x1080" width="100%" alt="First slide">
</div>
<div class="carousel-item">
<img class="img-fluid" src="http://via.placeholder.com/1920x1080" width="100%" alt="Second slide">
</div>
<div class="carousel-item">
<img class="img-fluid" src="http://via.placeholder.com/1920x1080" width="100%" alt="Third slide">
</div>
<a class="carousel-control-prev" href="#fullCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#fullCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
&#13;
答案 0 :(得分:1)
根据你的html文件尝试添加以下代码。 的说明强> 当你制作Carousel的位置:绝对顶部:0,它会在顶部,重叠所有html组件,现在使它全屏我们使用100%宽度。这里的导航栏现在不可见,但是它不是可见的,它在旋转木马后面,所以要使它可见,我们使用z-index:9;
.navbar{
z-index:9;
}
#fullCarousel{
position:absolute;
width:100%;
top:0;
}
我希望你明白。
答案 1 :(得分:0)
尝试更改绝对位置或Z索引。