If you are not using flex or grid elements, the element must be positioned for the z-index to work. 1
In other words, the position property must have a value other than static or z-index , which will be ignored. 2
Your second div is not located. Here are two options:
- add
position: relative to #normal or - give the positioned div a negative
z-index value
#fixed { background-color: red; width: 500px; height: 500px; position: fixed; z-index: 0; } #normal { background-color: lightblue; width: 500px; height: 500px; z-index: 1; position: relative; }
<div id = 'fixed'> I'm Fixed </div> <div id = 'normal'> I'm Normal </div>
See also: Basics of the z-index CSS Property
1 Although the z-index , as defined in CSS 2.1 , only applies to positioned elements, CSS 3 allows the z-index to work with grid elements and flex items , even if position static .
2 z-index property page in MDN
source share