Learn HTML step-by-step from A to Z or improve your professional skills.  Home HTML and CSS Tutorials Layering Images
Your Ad Here

Layering Images


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="/img_articles/8470/image1.gif"> </div>

<div id="under" style="left: 500px; top: 485px; position: absolute"> <img src="/img_articles/8470/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: Brian Fusco
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

HTML is Hyper Text Markup Language that is used to make hypermedia and hypertext documents for the Web. More HTML and CSS: Most Popular Materials | Fresh Materials | More HTML Tutorials at Markuptutorials.com

Add comments to "Layering Images"

Only registered users can write comment

No comments yet...