Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overlay images (png) within a website?

Tags:

html

overlay

png

I am trying to mount an image in the middle of another (slightly larger) image so that it appears to be within the larger image (a phone in this case). I am unsure of the proper way to make this happen and any help is much appreciated!

like image 766
Taylor Avatar asked Sep 02 '11 22:09

Taylor


People also ask

How do I overlay an image on another image in HTML?

Add CSS. Add a relative div placed in the flow of the page. Set the background image as relative so as the div knows how big it must be. Set the overlay as absolute, which will be relative to the upper-left edge of the first image.

How can I put a picture on top of another?

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.


1 Answers

You need to set the z-index css property.

HTML:

<img id="png1" src="png1.png" />
<img id="png2" src="png2.png" />

CSS:

#png1 {
    position:absolute;
    top:0;
    left:0;
    z-index:0;
}

#png2 {
    position:absolute;
    /*
    set top and left here
    */
    z-index:1;
}

Here's a demo: http://jsfiddle.net/AlienWebguy/6VSBv/

like image 110
AlienWebguy Avatar answered Sep 17 '22 16:09

AlienWebguy