I'm having trouble getting the bootstrap navigation and carousel to fit perfectly on the screen without any overflow. My goal is to have both elements occupy 100vh seamlessly, with no scrolling necessary.
My first attempt was adding img-fluid: 100vh;
, but this caused the carousel to overflow when I scrolled to the very top.
Next, I tried wrapping the Navigation and Carousel in a div and setting 100vh
to that element, but unfortunately, that solution didn't work either.
If you'd like to take a look at the code, it's available on Codepen as well. Thank you for your assistance. 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>
// more slides...
<!-- 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