【发布时间】:2017-03-08 05:25:54
【问题描述】:
所以我为我的网站使用了 100 vh 高的英雄图片。现在图像是绝对定位的,所以我可以在图像上相对于它定位其他元素,如徽标、导航和文本。在这个部分之后,我想用新的图像和其他文本开始新的部分,但是一旦我开始新的行、列并尝试用 h1 文本放置新图像,它就会隐藏在之前的图像后面。我的意思是我想要一个带有新图像的新部分,<h1> 文本出现在主图像下方,而不是重叠或隐藏在它下面,因为它现在正在隐藏。它没有浮动或任何东西,我的浮动已清除,所以我不明白为什么会发生这种情况。
这里有一些 codepen,所以你会明白发生了什么。
<div class="container-fluid clearfix">
<div class="row">
<div class="col-lg-12">
<div class="hero_img">
<img class="logo" src="assets/logo.png"></img>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".collapse">
☰
</button>
<div class="collapse">
<div class="col-xs-12">
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Lorem</a>
</li>
</ul>
</div>
</div>
<div class="black_box clearfix"><h1>Kolding Bike Marathon</h1></div>
<div class="black_box_sub clearfix"><p>Bring activity to your life again</p></div>
<button type="button" class="btn btn-outline-secondary">Register now</button>
<button type="button" class="btn btn-success">Learn more</button>
</div>
</div>
</div>
</div>
</div>
<div class="section_one">
<h1>heyyyyy</h1>
</div>
.hero_img {
background-image: url("assets/hero.jpg");
width: auto;
height: 100vh;
background-size: cover;
position: absolute;
top: 0;
left: 0;
z-index: 999;
overflow: hidden;
clear: both;
}
.hero_img {
width: 100%;
height: 100vh;
position: absolute;
top: 0;
}
.logo {
position: relative;
left: 20px;
top: 20px;
z-index: 1002;
width: 5%;
min-width: 50px;
}
.nav {
position: relative;
top: 0;
z-index: 1000;
margin-top: 20px;
/*margin-right: 15px;*/
padding: 20px;
/*float: right;*/
width: auto;
flex-direction: column;
background: #555;
/*width: 100%;*/
filter: opacity(0.93);
}
a {
text-decoration: none;
color: white;
display: block;
border-bottom: 1px solid #444;
}
a:hover {
color: #999;
}
.nav-item {
display: block;
}
.navbar-toggler {
/*float: right;*/
display: flex;
justify-content: right;
position: relative;
z-index: 1000;
margin-top: 15px;
margin-right: 15px;
color: white;
float: right;
}
.black_box {
position: relative;
width: 45%;
min-width: 400px;
text-align: center;
z-index: 1000;
background: black;
margin-top: 10%;
padding: 10px 30px;
clear: both;
}
.black_box h1 {
color: white;
/*font-family: 'PT Sans', sans-serif;*/
font-family: 'Montserrat', sans-serif;
font-weight: 600;
letter-spacing: 1.5px;
}
.black_box_sub {
position: relative;
width: 30%;
min-width: 310px;
text-align: center;
z-index: 1001;
background: black;
margin-top: 2%;
clear: both;
margin-left: 90px;
}
.black_box_sub p {
color: white;
padding: 5px 25px;
font-family: 'Montserrat', sans-serif;
text-transform: uppercase;
padding-top: 10px;
padding-bottom: 0px;
}
【问题讨论】:
-
我没听懂你在问什么,你能详细说明一下吗?也许有一张照片,现在是什么样子,你到底想要什么
-
我对“vh”测量不太熟悉,但我怀疑这可能与您的问题有关。您将图像设置为垂直查看高度的 100%,这可能不允许您在其下方放置内容。无论如何,您都可以使用 javascript 来获取窗口的高度,然后将其应用于您的图像 div,以便它们以像素为单位的确切高度......然后堆叠 div 应该没问题。事实上,您可以将相同的数字应用于绝对 div 层,它们都会整齐地堆叠。
-
抱歉,描述不清楚,伙计们。已经解决了。 Vh 测量单位与此无关。我给我的英雄图像位置绝对值是一个错误。它必须是相对位置,然后里面的所有元素都相对定位。现在我改变了属性,我可以看到主英雄图像下的新内容没有重叠。还是谢谢!
标签: html css twitter-bootstrap css-float css-position