【问题标题】:How to put an <img> behind a background-image如何将 <img> 放在背景图像后面
【发布时间】:2019-06-20 15:31:37
【问题描述】:

我正在尝试创建如下图所示的内容。上下图像是 2 个背景图像。中间的照片是&lt;img&gt;。问题是我似乎不知道如何将&lt;img&gt; 放在背景图像后面。我尝试了 z-index 但这似乎不起作用。我的代码是这样的:

/*first bg image*/
.detail-act {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-image: url(./assets/img/bg-beige-sm-detail_1.svg);
  background-size: 100% auto;
  background-position: top center;
  background-repeat: no-repeat;
  z-index: 99;
  padding-bottom: 3rem;
}
/* the <img> */
.detail-omslagfoto {
  z-index: -99;
}

/*second bg image*/
.volgende-voorstelling {
  background-image: url(./assets/img/bg-next-up-sm.svg);
  background-size: 100% auto;
  background-position: top center;
  background-repeat: no-repeat;
  padding: 4rem 0;
  margin-top: -10rem;
  z-index: 99;
}
<article class="detail-act">some content</article>
<img class="detail-omslagfoto" src="...">
<article class="volgende voorstelling">some content</article>

【问题讨论】:

  • 嗨,我试过了,但他们只使用图像而不是背景图像。无论如何我都试过了,但这似乎不起作用。
  • 再次感谢您的回答,但我的问题是将图像与背景图像相结合。 :)

标签: html css image background-image z-index


【解决方案1】:

您需要将position:relative 属性添加到.detail-omslagfoto 类。

.detail-omslagfoto {
     z-index: -99;
     position: relative;
 }

【讨论】:

  • 谢谢你,这成功了! :)
  • @LucasVerhoest 谢谢!
猜你喜欢
  • 1970-01-01
  • 2018-02-18
  • 2014-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多