views:

150

answers:

4

This property make me confuse.

well.. i searched in google:

What is the z-index?

The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed). Answer Source

What is the z-index uses?

The order of which the elements overlap one another. For that purpose, you can assign each element a number (z-index). The system is that an element with a higher number overlaps an element with a lower number. Answer Source

Ok i understand now , it organize the elements and we can use any number ... the higher z-index number appears on all elements..ok nice.

z-index and jquery..very simple and very nice

...but i noticed from the answers that it depend on position property, so -->...(google)..

What is the relation between z-index and position?

demo--> >>source

Ok ... so z-index and position are couple..must be together..

need more information ::

dose it make any conflicts in browsers(IE7,IE8,chrome,...etc)?

What are the z-index uses or what can we do with z-index(depending on the Tags)?

...etc?

correct me if i understand wrong...

Thanks in advance.

+2  A: 

I would suggest to have a look at this property on SmashingMagzine.

The Z-Index CSS Property: A Comprehensive Look

It covers all nuts and bolts of this property with great examples and demonstrations.

Sarfraz
amazing...but i don't think that" It covers all nuts and bolts of this property "..... i'll read more..thanks
jjj
@jjj: what's it missing, it will be great know if you could share :)
Sarfraz
@Sarfraz.. i don't know yet... i am looking for more info
jjj
A: 

the most important thing to remember is that z-index works ONLY if the element has position relative, absolute or fixed

pixeltocode
+1  A: 

I'm not entirely sure what you're asking but for the most-part you only ever need to use z-index if you're doing complicated styling e.g. hover tooltips or dropdown navigations, simply to ensure that they display over other page content.

For basic designing you should generally be avoiding using the position and z-index properties as you can usually achieve the same effects with better performance and browser compatibility with just floats etc.

The Smashing Magazine link posted by Sarfraz is an excellent article on the topic and a good point of reference if you're still struggling to understand the functionality of the property.

Steve
oh.."avoiding"..why ?(explain more)...i mean ,depending on what i read , it is simple elements organizer..!!
jjj
I only tend to avoid it because for the most part of design it is unnecessary and it behaves pretty inconsistently between browsers and you end up spending time making it work in legacy ones. By all means use it if you need to, but if you're not doing dropdowns/tooltips/something else of the like I fail to see why you'd need to.
Steve
@ Steve...so.. it does make conflicts on browsers..?
jjj
I wouldn't say it makes conflicts on browsers, but as stated above various versions of IE have different z-index defaults and behave differently around it.
Steve
oh...good to know that..thanks
jjj
+2  A: 

Z-index is the property that determines which html element appears on top of antoher html element when they overlap. The basic idea is that the element with the highest z-index is "on top".

By default, elements have a z-index of zero, but setting the css property on one element to 1, and another to 5 will make the latter element be "on top" of the former, if they overlap.

So far, so simple, but there are several things to look out for.

One, as already mentioned in another answer, is that z-index only has an effect if the element is positioned with position absolute, fixed or relative. (i.e. the css property "position"). An unpositioned element has a z-index of zero.

To complicate things further (and in my experience the area that is often not understood) is the concept of the stacking context. More info can be found in articles such as this. In short though, each time you explicityly set a new z-index, you start a new stacking context. All child elements of the one on which the z-index was set are now in this new stating context, which may be above or below a stacking context on another unreleated element.

What does this stacking context mean? It means that an element with a z-index of 100 is not necesarily on top of an element with z-index of 1. If they are in different stacking contexts, only the z-index of the stacking context's themselves matters.

Rob Levine
thank you for making that simple for me ... but i have a Q: you said "each time you explicitly set a new z-index, you start a new stacking context">> does that make the website Heavier or something like that?
jjj
when you say "heavier" I think you mean "does it make it more heavyweight/slower". The truth is I've never checked if it slows rendering (or increases memory usage) to have many stacking contexts, but even if it does (which I'm not sure it does), I'd expect the effect to be very small. Generally speaking, your page won't end up with too many stacking contexts anyway. If you are having to set z-index all over the place, it is probably a sign that the page needs redesigning. Generally speaking, even on complex pages with overlapping stuff, I only set z-index in a handful of places.
Rob Levine
@Rob Levine..thanks..i hope someone assures us that it doesn't..
jjj