我有一个包含图片的HTML表格,需要在每个图片上覆盖一个小图标。我们可以使用z-index和定位来实现这一点。
.under {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
.over {
position: absolute;
left: 40px;
top: 10px;
z-index: -1;
}
<img src="https://tafttest.com/184x46.png" width="184" height="46" class="under" />
<img src="https://tafttest.com/100x84.png" width="100" height="84" class="over" />
您可以使用position:relative
,并设置right:30px
和bottom:30px
,这将使其向上和向左移动30像素。
CSS:
.icon{
position:relative;
right:30px;
bottom:30px;
}
你想置于顶部的元素需要具有更高的z-index值。
因此,小图标应该具有2的z-index值,而图像应该具有1的z-index值。
例如:
.icon {
z-index: 2;
position: relative;
left: 30px;
top: 30px;
}
.images {
z-index: 1;
}