Managing the Stacking Order of Elements
The z-index property determines the stacking order of positioned elements on a web page. It only applies to positioned elements, which have a position value of absolute, fixed, relative, or sticky. As the elements are taken out of the normal document flow, to determine which of these positioned elements should be displayed higher or lower, we specify z-index.
z-index: number_without_units
The higher value the z-index property has, the higher the element is shown on the user screen.
Let's practice. We have four div elements with the box class, each styled as a square and numbered to represent their order in the html document. The squares are currently positioned on top of each other. The task is to adjust the z-index property with the correct values to bring square 3 to the front and send square 4 to the back.
index.html
index.css
Note
If we set the same value for the
z-indexproperty to different elements, the browser will show the elements in the order in which the elements are in thehtmlfile.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
How do I set the z-index values to bring square 3 to the front and square 4 to the back?
Can you explain what happens if two elements have the same z-index value?
Can you show an example of how the z-index property is used in CSS?
Awesome!
Completion rate improved to 2.04
Managing the Stacking Order of Elements
Swipe to show menu
The z-index property determines the stacking order of positioned elements on a web page. It only applies to positioned elements, which have a position value of absolute, fixed, relative, or sticky. As the elements are taken out of the normal document flow, to determine which of these positioned elements should be displayed higher or lower, we specify z-index.
z-index: number_without_units
The higher value the z-index property has, the higher the element is shown on the user screen.
Let's practice. We have four div elements with the box class, each styled as a square and numbered to represent their order in the html document. The squares are currently positioned on top of each other. The task is to adjust the z-index property with the correct values to bring square 3 to the front and send square 4 to the back.
index.html
index.css
Note
If we set the same value for the
z-indexproperty to different elements, the browser will show the elements in the order in which the elements are in thehtmlfile.
Thanks for your feedback!