gpt4 book ai didi

css - 如何使 Bootstrap Navigation 和 Carousel 以 100vh 配合在一起?

转载 作者:行者123 更新时间:2023-11-27 23:56:05 25 4
gpt4 key购买 nike

我正在尝试将引导导航和旋转木马放在屏幕上而不出现任何溢出。换句话说,我希望导航和旋转木马在 100vh 内适合在一起而没有任何溢出。

我尝试添加 img-fluid: 100vh; 但是当我一直滚动到顶部时这会使轮播溢出。

我还尝试在导航和旋转木马周围添加一个 div,并尝试向其添加一个 100vh,但这没有用。

这也是codepen中的代码。感谢您的帮助。 https://codepen.io/christiangutierrezreyez/pen/vwpQdN

<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!--BOOTSTRAP CSS-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- FONTAWESOME CSS -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<!--TITLE-->
<title>Document</title>

<!-- CUSTOM CSS -->
<style>
.img-fluid {
height: 100vh;
}
</style>
</head>

<body>
<!-- BODY -->
<div id="navslider-vh"></div>
<!-- NAVIGATION -->
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-3">
<div class="container">
<!-- BRAND -->
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<!-- LINK 1 -->
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<!-- LINK 2 -->
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<!-- LINK 3 -->
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<!-- LINK 4 -->
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- END NAVIGATION -->


<!-- CAROUSEL -->
<div id="MagicCarousel" class="carousel slide" data-ride="carousel">
<!-- CAROUSEL INDICATORS-->
<ol class="carousel-indicators">
<li data-target="#MagicCarousel" data-slide-to="0" class="active"></li>
<li data-target="#MagicCarousel" data-slide-to="1"></li>
<li data-target="#MagicCarousel" data-slide-to="2"></li>
<li data-target="#MagicCarousel" data-slide-to="3"></li>
<li data-target="#MagicCarousel" data-slide-to="4"></li>
</ol> <!-- END CAROUSEL INDICATORS-->
<div class="carousel-inner" role="listbox">
<!-- SLIDE 1 -->
<div class="carousel-item active">
<img class="d-block w-100 img-fluid" src="https://source.unsplash.com/random/1920x1080" alt="First Slide">
<div class="carousel-caption">
<h3>Cinderalla</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- SLIDE 2 -->
<div class="carousel-item">
<img class="d-block w-100 img-fluid" src="https://source.unsplash.com/random/1920x1080" alt="Second Slide">
<div class="carousel-caption">
<h3>Cinderalla</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- SLIDE 3 -->
<div class="carousel-item">
<img class="d-block w-100" src="https://source.unsplash.com/random/1920x1080" alt="Third Slide">
<div class="carousel-caption">
<h3>Snow White</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- SLIDE 4 -->
<div class="carousel-item">
<img class="d-block w-100 img-fluid" src="https://source.unsplash.com/random/1920x1080" alt="Fourth Slide">
<div class="carousel-caption">
<h3>Snow White</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- SLIDE 5 -->
<div class="carousel-item">
<img class="d-block w-100 img-fluid" src="https://source.unsplash.com/random/1920x1080" alt="Fifth Slide">
<div class="carousel-caption">
<h3>Beauty and the Beast</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- SLIDE 6 -->
<div class="carousel-item">
<img class="d-block w-100 img-fluid" src="https://source.unsplash.com/random/1920x1080" alt="Sixth Slide">
<div class="carousel-caption">
<h3>Pokahauntes</h3>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>

<!-- CONTROLS -->
<a href="#MagicCarousel" role="button" data-slide="prev" class="carousel-control-prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a href="#MagicCarousel" role="button" data-slide="next" class="carousel-control-next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>


</div><!-- END CAROUSEL INNER -->
</div><!-- END CAROUSEL -->
</div> <!-- END NAVSLIDER-VH -->>

</body> <!-- END OF BODY -->
<!-- JQUERY JS-->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

<!-- POPPER JS-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

<!-- BOOTSTRAP JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</html>


[1]: https://codepen.io/christiangutierrezreyez/pen/vwpQdN

最佳答案

如果您从 nav 中删除 mb-3 类,那么此 css 将起作用:

#MagicCarousel,
#MagicCarousel > div,
#MagicCarousel > div > div > img{
height: calc(100vh - 56px);
}

...其中“56px”是 nav

的高度

关于css - 如何使 Bootstrap Navigation 和 Carousel 以 100vh 配合在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56264178/

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