Image Overlapping with CSS How to do

Image Overlapping With CSS How to Do ?

In this tutorial we are going to test how to do play with css and image and make them overlapped. Also we will test mouse hover effect.

So we took 4 alphabet images in PNG format ( We took PNG with transparent background )

Here are our Images.

alphabet a alphabet b alphabet c alphabet d

So lets start with our html and css and make them overlap like this image below.

image overlap with css

Here is our HTML code and CSS code for this.

<div>
    <img src="a.png" class="alphaa" />
    <img src="b.png" class="alphab" />
    <img src="c.png" class="alphac" />
    <img src="d.png" class="alphad" />	
</div>
.alphab{position:relative;left:-160px;top:80px;}
.alphac{position:relative;left:-360px;top:180px;}
.alphad{position:relative;left:-560px;top:280px;}

in our css code first important part is positioning and second important is from where to set position. So we use left and top

Lets play with another css increment and to add Mouse over effects on same CSS. So we are going to add :hover effect on those css

.alphaa{position:relative;left:0px;top:0px;z-index:1}
.alphab{position:relative;left:-160px;top:80px;z-index:1}
.alphac{position:relative;left:-360px;top:180px;z-index:2}
.alphad{position:relative;left:-560px;top:280px;z-index:3}
.alphaa:hover{z-index:4;}
.alphab:hover{z-index:4;}
.alphac:hover{z-index:4;}

with this modified code if we hover mouse over any alphabet it will overlap others and visible in full due to presence of z-index and its value. Like the image below.

 

on mouse over overlap image

 

this is how we can play with our images and css to make overlapping of images , and can design our collages , image galleries and other presentations on web pages.

Leave a Reply

Your email address will not be published. Required fields are marked *

5  ×  3  =