为什么空间不被整个div占用?

时间:2018-03-17 12:03:42

标签: html css bootstrap-4

我在halfHero类中添加了display:block;。为什么不占用空间并使用hr的容器低于整个div?我希望半英雄占据空间,以便将容器推下来。

Here is the image of the situation.

以下是相关代码:

 .semiHero {
        background-image: url("../assets/semiHero.png");
        height: 50%;
        width: 100%;
        background-position: center;
        background-repeat: scroll;
        background-size: cover;
        position: absolute;
        display: block;
    }
       <div class="semiHero">
            <div class="container" id="NavMain">
                <nav class="navbar navbar-custom navbar-expand-lg navbar-light">
                    <a class="navbar-brand" href="#">Logo</a>
                    <button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav"
                        aria-expanded="false" aria-label="Toggle navigation" id="hamburger">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse justify-content-end" id="navbarNav">
                        <ul class="navbar-nav navbar-custom">
                            <li class="nav-item active">
                                <a class="nav-link" href="#">Start
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#">About Me</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#">Work</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#">Contact</a>
                            </li>
                        </ul>
                    </div>
                </nav>
                <div class="hero-text">
                    <h1>May I Introduce Myself?</h1>
                    <hr>
                    <h2>Frontend Design | UI/UX Design</h2>
                    <br>
                </div>
            </div>
            <button id="goAhead">Go Ahead</button>
        </div>
        <!-- MainSection -->
        <div class="container">
            <div class="row">
                <div class="col" id="Name">
                    <h1>
                        Raphael Lechner.
                    </h1>
                </div>
            </div>
        </div>

1 个答案:

答案 0 :(得分:0)

position: absolute定位特定元素相对于它最近的祖先。 这就是为什么元素从页面流中移除而不占用任何空间的原因。