iDaniel19 iDaniel19 - 30 days ago 12
CSS Question

Bootstrap jumbotron full height without navbar's height

HTML:

<!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>


<div class="jumbotron jumbotron-fluid vertical-center">
<div class="container">
<h1 class="display-3">TITLE</h1>
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
<hr class="my-4">
<p>Description text</p>
<p class="lead">
<a class="btn btn-primary btn-lg btn-jumbotron" href="#" role="button">Learn more</a>
</p>
</div>
</div>

<div class="container">

</div> <!-- /container -->


CSS:

.navbar{
padding: 7px 0;
margin-bottom: 0;
}

.jumbotron {
background-image: url(http://cdn.wallpapersafari.com/97/93/UE7u4i.jpg);
background-size: cover;
color: white;
margin: 0;
}

.vertical-center {
min-height: 100%; /* Fallback for browsers do NOT support vh unit */
min-height: 100vh; /* These two lines are counted as one :-) */

display: flex;
align-items: center;
}

.btn-jumbotron{
background-color: black;
border-color: white;
}


I'm trying to have a jumbotron have full height of the browser's window, but without the height of the static navbar. I did get it to size of full viewport by using
height: min-height:100vh
amnd center it, but as you can see from the jsfiddle example I have a scrollbar present because of the navbar's height -
64px
.

How can I remove that?

https://jsfiddle.net/iDaniel19/12qxmkjt/

Answer Source

Use calc

.vertical-center {
min-height: 100%;  /* Fallback for browsers do NOT support vh unit */
min-height: 100vh; /* These two lines are counted as one :-)       */

min-height: calc(100% - 64px);  /*  */
min-height: calc(100vh - 64px); /* */

display: flex;
align-items: center;

}