Search code examples
htmlcssparallax

How to get DIV Beneath Other DIVs in Hierarchy?


I'm having trouble with the order of layered DIV elements. I have a DIV .lens-flare that's at the bottom of the hierarchy in HTML. Yet when I transform: translate the position so it encompasses the entire parent DIV, it shows above elements that are above it in the hierarchy.

So I tried setting z-indexes, and then turned my translate into translate3d. Still I'm not able to get .lens-flare underneath .top-nav-bar, .nav-bar, or .cta.

Currently I have a pointer-events: none applied so I can at least click on the things underneath. But how can i actually move the .lens-flare layer under everything else successfully?

Here's my CodePen for the project


Solution

  • Elements rendered later are considered being closer to the screen than the elements rendered before them.

    Z-index is the answer if you want to change this, you just need to remember z-index works only with elements that are positioned.

    .lens-flare
      position: relative
      z-index: 1
    
    .nav-bar, .top-nav-bar, .cta
      position: relative
      z-index: 2
    

    Your corrected codepen: http://codepen.io/sEvher/pen/doyWoW