website promotion banner
eturnkeys
Your Ad Here
HTML and CSS  Home HTML and CSS Tutorials Layering Images
rss

Layering Images

Author: Brian Fusco More by this author


The code about to be described can make pixel perfect content placement possible.

Say you have two images, like the two images below:

Image 1 Image 2

But, you want them to be on top of each other to form a cross like the one below:

Image3

How did I do that? Magic, you say? Nope, all I did was add a couple of <div> tags. Here is the code:

<div id="top" style="left: 500px; top: 485px; position: absolute"> <img src="image1.gif"> </div>

<div id="under" style="left: 500px; top: 485px; position: absolute"> <img src="image2.gif"> </div>

First, you must give your div a name, which the id attribute does. The style attribute will define the position of the whole layer of content the falls inside the <div> tag. There are only a few things that you have to remember:

  • The left function positions the image x number of pixels from the left of the browser to the left side of the image.
  • The top function positions the image x number of pixels from the top of the browser to the top of the image.
  • Remember to put position: absolute in because if you do not, the position will default to the position: relative setting which is more difficult to work with and can cause some varying placements in different browsers.

That's all you need to know. Layer it up!



Author's URL: www.spoono.com

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Add comments to "Layering Images"