html - z-index > css 背景图像 > 绝对 img > p 标签

标签 html css

如何将我的 p 标签放在最上面?

这是我的代码

HTML
    <section class="key-fundamentals">
        <div class="container">
        <img class="img-man-cbox img-responsive" src="images/img-man-cbox.png">
            <p>Our key fundamentals</p>
        </div>
    </section>

CSS

.key-fundamentals {
 z-index: -999;
 height: 535px;
 background-image: url('../images/bg-fundamentals.png');
 background-position: center;
 background-repeat: no-repeat;
}
.key-fundamentals .img-man-cbox {
  z-index: 1;
  position: absolute;
  top: 782px;
  left: 80px;
}
.key-fundamentals p{
 z-index: 2;
 color: red;
}

h1标签绝对低于img2图片
当我将 zindex -1 放入 img2 时,图像将消失。

请帮忙..谢谢!

提前致谢...

最佳答案

要使 z-index 起作用,元素需要一个不同于 static 的位置

.key-fundamentals p {
 position: relative;         /*  added property  */
 z-index: 2;
 color: red;
}

.key-fundamentals {
  z-index: -999;
  height: 535px;
  background-image: url('../images/bg-fundamentals.png');
  background-position: center;
  background-repeat: no-repeat;
}

.key-fundamentals .img-man-cbox {
  z-index: 1;
  position: absolute;
}

.key-fundamentals p {
  position: relative;
  z-index: 2;
  color: red;
}
<section class="key-fundamentals">
  <div class="container">
    <img class="img-man-cbox img-responsive" src="http://placehold.it/150/ddd">
    <p>Our key fundamentals</p>
  </div>
</section>

关于html - z-index > css 背景图像 > 绝对 img > p 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43437537/

相关文章:

html - 根据 Foundation 5 中的内容设置 DIV 的宽度

html - css 适用于 Firefox/Chrome,但不适用于 IE

HTML+CSS 文本容器设计

html - 如何在 Google map 上方使用 Bootstrap 定位内联文本框和按钮?

javascript - 如何保存可拖动对象的位置

jquery - 如何使用按钮关闭折叠

css - float 不影响兄弟 div 的段落。

html - Bootstrap 的选项卡未居中对齐

html - 是否可以向 HTML5 Canvas 上绘制的图像添加工具提示?

html - 具有混合列数的响应式设计