身体内容背后的英雄形象

问题描述 投票:2回答:1

出于某种原因,我的英雄形象落后于我的身体内容。如何修复,以便英雄形象推动我的身体内容。我尝试了z-index但是没有用(我的英雄图像有可变的自动高度)。

.hero .hero-bg, .hero {
    width: 100%;
    height: 100%;
}

.hero .hero-bg {
	background-image:url('http://via.placeholder.com/1000x300');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center 80%;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 1;
}

html {
    width: 100%;
    height: 100%;
    color: red;
}

body {
    background-color: green;
}
<body>
<section class="hero">
<div class="hero-bg">
</div>
</section>
<section class="content">
<p> content - content - content - content - content - content - content - content - content - content - content - content - content</p>
</section>
</body>
html css html5 css3
1个回答
1
投票

原因是因为你给你的图像position: absolute;,所以它将落后于其他内容。

我在HTML中添加了一些额外的内容,因此很明显其余内容与.hero部分不重叠:

body,
html {
  width: 100%;
  height: 100%;
  margin: 0;
  color: red;
}

body {
  background-color: green;
}

.hero,
.hero-bg,
.content {
  height: 100%;
}

.hero-bg {
  background-image: url('http://via.placeholder.com/1000x300');
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center 80%;
  opacity: 1;
}
<section class="hero">
  <div class="hero-bg"></div>
</section>

<section class="content">
  <div>Other content</div>
</section>
© www.soinside.com 2019 - 2024. All rights reserved.