Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we overlap two images using css style?

Tags:

html

css

image

I have a list of images in an html table and need to overlap a small icon on each image. How can we do this using z index and positioning?

like image 278
random Avatar asked Nov 23 '09 11:11

random


People also ask

How do you make two images overlap in HTML?

We're applying a negative right margin on a floated left element that allows content to overlap. -100% is equal to the width of the container so it shifts the image to the left and allows the bottom image to render beneath it as if it's not in the DOM. Codepen here: HTML.

How do you blend two images in CSS?

Background blend mode with two images It's as easy as adding two background images in the CSS declaration. The next choice is to have a background color (or not). If you do not want a background color, this can be removed and the images will blend together depending on the blend mode that you choose.

How do you overlap multiple pictures?

You can easily put a photo on top of another photo using Fotor, a free online photo editor. Simply drag and drop the image you want to overlay into Fotor- this will become your background picture. Then add a new image over it. You can adjust the transparency levels to blend two images together perfectly.


3 Answers

.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" />
like image 115
Jitendra Vyas Avatar answered Oct 13 '22 15:10

Jitendra Vyas


The element you want to be on top needs to have a higher z-index

So the small icon would have a z-index of 2 and the images would have a z-index of 1

Example:

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

.images {
  z-index: 1;
}
like image 34
zeckdude Avatar answered Oct 13 '22 16:10

zeckdude


You could use position:relative and set right:30px, bottom:30px, that would shift it up and left by 30 pixels.

CSS:

.icon{
position:relative;
right:30px;
bottom:30px;
}
like image 38
noirenex Avatar answered Oct 13 '22 16:10

noirenex