gpt4 book ai didi

html - 为什么空间没有被整个div占用?

转载 作者:行者123 更新时间:2023-11-28 02:00:51 24 4
gpt4 key购买 nike

我在 semiHero 类中添加了一个 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>

最佳答案

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

关于html - 为什么空间没有被整个div占用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49335770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com