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;
}


我正在尝试让超大型导航器具有浏览器窗口的全高,但没有静态导航栏的高度。我确实通过使用height: min-height:100vh将其设置为整个视口的大小,但将其居中,但是正如您从jsfiddle示例中看到的那样,由于导航栏的高度-64px,所以存在一个滚动条。

我该如何删除?

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

最佳答案

使用计算

.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;


}

关于html - Bootstrap Jumbotron全高,没有导航栏的高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45785795/

10-12 00:08
查看更多