css - 我可以在 <div> 顶部添加图像而不添加任何 html 标签吗?

标签 css background z-index

假设我们有

<div class="picture"><img class="picture_thumb" src="path" /> </div>

我想使用 CSS 将图像 z-index 添加到 .picture 中(它基本上是一个放大镜图标,所以我可以在顶部看到它.picture_thumb)

有机会吗?

非常感谢

PD:它会像一个 Front-ground 而不是背景 -编辑- 一张图让你更好理解 enter image description here

最佳答案

没有前台这样的东西。

你必须这样做:

<div class="picture">
  <img src="images/picture.jpg" alt="Picture" />
  <img class="magnifier" src="images/magnifier.jpg" alt="Maginfy" />
</div>

.picture {
  position: relative;
  width: 100px;
  height: 100px;
}

.magnifier {
  position: absolute;
  bottom: 0px;
  right: 0px;
  z-index: 1000;
}

如果您不想将放大镜图像添加到每个图片 div,您也可以使用 javascript 来实现。

关于css - 我可以在 <div> 顶部添加图像而不添加任何 html 标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7146282/

相关文章:

HTML 中的 PHP WordPress Foreach H2 标题

javascript - 隐藏选择菜单并使用按钮打开

Css 过渡和 div

html - 透明盒子,穿过它后面的盒子

html - 尽管在样式表中被设置为 0,但边距仍然存在 - CSS

css - 使用css3或技巧的特殊滚动条设计

Android 背景图片大于容器

background - 在后台脚本中运行 busybox netcat?

html - Z-Index/定位未按预期工作

swift - 如何更改 UIView 的 z 索引或堆栈顺序?