How to use z-indexing in CSS

7 Apr 2010 | Posted by: Keir Cleland
How to use  z-indexing in CSS

You may find when using CSS positioning that, on occasion, you may end up with layers that overlap. sometime this can be a required element to the design of your layout. But what if you want the first or second layer to be top, not the last one you've positioned? This is when the z-index property comes into play.

Z-index? What?

Think of each positioned layer of you design as pieces of paper. You can lay them one on top of the other in whatever order you like... using the z-index of course. The higher the z-index the closer to the top of the "paper pile" it is going to be. you can even use negative numbers to get the positioned element right down to the bottom. Cool huh?

Umm... examples please

Right, quite simply you will need to have some css positioned elements. These will HAVE to have the position attribute set. The z-index will work with either relative or absolute positioned elements. For example:

#container {
    position:absolute;
    width:100px;
    height:100px;
    z-index:-1;
}


This container will position itelf below the previous element. Use a positive number and the element will be above.
Easy Peasy!

 


 

Please rate this article

Click the stars below to give this article a mark out of 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 5 / 10


Related Articles

Creating a conditional CSS with PHP
9 Mar 2011 | Posted by: Paul Whittington
Creating a conditional CSS file, mainly to avoid the issues of IE6 but also to allow easier modifications to mobile device stylesheets.
66% rating, 0 comments



Post your comments...

We would really appreciate any comments or additions that you have. Include a link in your comment and if we think your comment is appropriate we will publish it. If found this article in any way useful we would really appreciate you bookmarking the page with any of the social bookmarking links provided.



Name:
(optional, shown on site)
Email:
(optional, never shown on site)
Code:
(case sensitive)
captcha
Your feedback: