Bootstrap jumbotron全高度,没有导航栏的高度

时间:2017-08-20 18:57:30

标签: html css twitter-bootstrap

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

我正在尝试让jumbotron拥有浏览器窗口的全高,但没有静态导航栏的高度。我确实通过使用height: min-height:100vh和它的中心将它设置为完整视口的大小,但正如你可以从jsfiddle示例中看到的那样,由于导航栏的高度 - 64px,我有一个滚动条。

我该如何删除?

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

2 个答案:

答案 0 :(得分:1)

使用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;

}

答案 1 :(得分:0)

添加到.navbar位置:绝对;顶部:0;宽度:100%;和填充顶部:64px;到.jumbotron