DivitoDesign

Everything for the Web Professional

Z-Index : Overlap HTML Elements With CSS

Information about the Author:

Name:

URL: http://twitter.com/divitodesign

Description enjoy design, write articles, like typography, love football, keep chilling.

More on: CSS

48 Comments

  1. great post!! your blog is very good… congratulations…

  2. Avangelist says:

    Hmmmm…
    Pink on white, never a good idea. and I am almost certain that height is not a cross browser compliant command anymore.

    But at least you have taken the time to write something which is more than me.

  3. @Avangelist – Pink on white? What are you talking about? Height not cross browser compliant? I don’t understand your comment.

    tincho 1492 | Martín – Thanks for that comment. :)

  4. Helle Stefan

    I stumbled over your blog following a link from a Danish weblog. I actually like the content here – especially your CSS guides. Keep’em comming!

    Tot ziens from Denmark

  5. Hello!

    Thanks for visiting and thank you for your compliment! I have visited your blog as well, but unfortunately I can’t understand Danish.

    Tot ziens from Holland!

  6. rob says:

    Is there a way to do this without using style sheets?

    Would you try content or something like that?

  7. rob says:

    oops i put something in code before and after the word “content” in that comment, so you cant see it :\

  8. @Rob – There is a way, when using Inline CSS. You should style the div like this:

    < *div style="z-index:1; position:absolute;">< */div>
    and div 2:
    < *div style="z-index:10; position:absolute;">< */div>

    It sure is available without CSS, (via Javascript I guess) but that makes things a lot harder. Try using this way, and if you want to know anything else, let me know.

    * remove the star (WordPress won’t allow me to post codes.)

  9. oli says:

    Thank you for this tip. Will have to experiment with this when I come to design some web pages. I never really knew that this was possible but it looks interesting.

  10. Thanks, you do that. :)

  11. CoderPhase says:

    Is css worth taking a year to learn or how long does it actually take to learn. I am just wondering cause this article really dragged me into it and im just wondering if it is easier to hire someone to do css work for me, or should i learn it and therefore save money. Let me know your opinion Please.

    ps – for Webwork visit http://www.CoderPhase.com and meet the best freelancers now.

    Regards

  12. Most Excellent! This will definitely help me when i’m creating wordpress themes!!

    Thank you

  13. Bebo Skins says:

    thanks for this, i have bookmarked your site and look forawrd to seeing more tutorials :D

    thanks once again.

    Bebo Skins !

  14. Awesome tip. This will do wonders for our themes. thanks again admin

  15. Thanks for your reminder, i’ve been using z-index for a while now. :)

  16. Very informative post. Great step-by-step guide for people to follow.

    Keep them coming :)

  17. prashant moulik says:

    this example not supported for all web browser.

  18. Internet fax says:

    good tips, i really like css and this is help me in my project. thanx!

  19. Great stuff, i always like to learn more about css or just get a different perspective. I will come back and read more

  20. Thanks for this post, i will test it now!

  21. ive been looking for something like this for ages and have seriously had to changes my designs big time because i wasnt sure how to code the layout to overlap but with this it now will, thanks!!

  22. Sumesh says:

    Z-index, when used cleverly, can be a powerful tool. I remember drooling over overlaid images and div elements on some websites back when I didn’t know about Z-index.

    And lets face it, Z-index hasn’t been very well documented, now has it? Much like everything else advanced in CSS. Bummer…

  23. i3l1nd3d says:

    Z-Index is very important but is it supported under all doctypes?

    Freelance web design – David Leonard Tampa bay web design

  24. Sarah Volker says:

    Maybe with this post more people will utilize the power of Z-index. It will make for stronger, faster webpages won’t it?

  25. Ibrahim Nisar says:

    Hi!
    first of all thanks for the nice blog post about z-index. it really came useful. i have a query about using z-index in a css slider on my website.

    actually i need to make the slider lower z-indexed and a button “read more” higher so that the slider changes while the button keeps it place all the time.

    is it possible
    Thanks again

  26. naveen says:

    z-index also work with position:fixed;

  27. Møbler says:

    I wish i found this blog 3 months ago, the z-index were about to make my go crasy this summer. UR now bookmarked! I’ll be back

  28. Ruhul Amin says:

    Sounds Good……………..

  29. Michel Kogan says:

    thanks for last sentence : “You should always remember to add a position:absolute; property, or your Z-index will not work!”

  30. Dany says:

    Great tutorial but did I miss something; I couldn’t see and example of the final “correct” version?

  31. that tricky little position property makes all the difference. Another article with a good link to a full explanation here:

    http://onegiantmedia.com/css-z-index-not-working-to-order-depth-position-of-div

    cheers

  32. Aniket Kamthe says:

    Thank you so much for your help. This is really help me in time. Thanks a lot.

  33. Erick S. says:

    This seems nice…but…

    When you scroll with the browserwindow scrollbar, the DIV with ‘position:absolute;’ stays on the same place while the rest scrolls.

    Or am I doing something wrong?

  34. bill says:

    please rewrite the beginning of this article as it is wrong and is sure to be causing confusion.

    the assertion that the zindex is not working in your first example is wrong, and your use of the term ‘under’ in this manner shows that you are yourself confused about this property.

    zindex does not deal with the FLOW of the elements; it only deals with the order of OVERLAPPING elements. your first example has no OVERLAPPING elements, therefore the zindex has no discernible affect, which is proper.

    and you do not need to have absolute positioning for zindex to work. any overlapping elements will be affected by zindex and absolute positioning is not the only way for that to occur.

    given how high this page ranks in google, you would be doing a lot of people a favor by removing/rewriting the misleading portions.

    thanks.

  35. Richard says:

    It still worked when one of my elements was “position relative.”

    Thx!

  36. zemelapis says:

    it doesnt work for me anyway, cant get what i’m doing wrong!

    • zemelapis says:

      sorry found the problem and i am sure many had it, by default for example div is transperant, so it looks like doesnt overlap, but when u put background it works fine.

  37. I know Bill said your instructions were wrong (see above) but they worked for me. Wrong or right, I appreciate the help.

  38. Benedict says:

    I have a z-index issue when I move the navigation links over to the right, under the dropdown box. I need the links to go behind the drop down box.
    The links are absolutely positioned with a z-index: -9999 !important but I still can’t get it to work.

    http://www.selected.telegraph.co.uk/

Please Respond and Give your Opinion

We use Gravatar to handle our avatars. Get one there!