微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – CSS显示div背景图像顶部其他包含的元素

参见英文答案 > CSS background image on top of <img>
不知道如果这是可能的,怎么样,但是我试着用我的代码中的元素的z-index玩弄没有成功。

我有一个div元素,在css中设置了一个背景图像。在div里面,我有其他元素,像div和img。我试图让包含背景图像的主要div保持在顶部,因为我想要的背景图像显示在其他元素的顶部(这个背景图像有一些圆角,我想显示在图像的顶部在这个div)。

示例HTML:

<div id="mainWrapperDivWithBGImage">
   <div id="anotherDiv">
      <!-- show this img behind the background image 
      of the #mainWrapperDivWithBGImage div -->
      <img src="myLargeImage.jpg" />
   </div>
</div>

示例CSS:

/* How can I make the bg image of this div show on top of other elements contained
   Is this even possible? */

#mainWrapperDivWithBGImage {
  background: url("myImageWithRoundedCorners.jpg") no-repeat scroll 0 0 transparent;
  height: 248px;
  margin: 0;
  overflow: hidden;
  padding: 3px 0 0 3px;
  width: 996px;
}

解决方法

我会把一个绝对定位,z指数:100;具有背景的跨度(或跨度):url(“myImageWithRoundedCorners.jpg”);在#mainWrapperDivWithBGImage中设置它。

原文地址:https://www.jb51.cc/html/233260.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐