身体内容背后的英雄形象

时间:2018-06-04 12:49:23

标签: html css html5 css3

出于某种原因,我的英雄形象落后于我的身体内容。如何修复,以便英雄形象推动我的身体内容。我试过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>

1 个答案:

答案 0 :(得分: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>

相关问题