简体   繁体   English

我们如何使用css样式重叠两个图像?

[英]How can we overlap two images using css style?

I have a list of images in an html table and need to overlap a small icon on each image. 我在html表格中有一个图像列表,需要在每个图像上重叠一个小图标。 How can we do this using z index and positioning? 我们如何使用z索引和定位来做到这一点?

 .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" /> 

The element you want to be on top needs to have a higher z-index 您希望位于顶部的元素需要具有更高的z-index

So the small icon would have a z-index of 2 and the images would have a z-index of 1 因此,小图标的z-index为2,图像的z-index为1

Example: 例:

.icon {
  z-index: 2;
  position: relative;
  left: 30px;
  top: 30px;
}

.images {
  z-index: 1;
}

You could use position:relative and set right:30px , bottom:30px , that would shift it up and left by 30 pixels. 你可以使用position:relative和set right:30pxbottom:30px ,它会将它向上移动并向左移动30个像素。

CSS: CSS:

.icon{
position:relative;
right:30px;
bottom:30px;
}

Here is an guide about you can use z-index and here https://developer.mozilla.org/en/understanding_css_z-index 以下是关于您可以使用z-index的指南,请访问https://developer.mozilla.org/en/understanding_css_z-index

an article about positioning http://www.tizag.com/cssT/position.php 关于定位的文章http://www.tizag.com/cssT/position.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM