Complete the code to set the stacking order of an element with z-index.
div {
position: relative;
z-index: [1];
}The z-index property accepts integer values to set stacking order. Here, 10 sets a positive stacking order.
Complete the code to make the element appear behind others using z-index.
header {
position: absolute;
z-index: [1];
}Negative z-index values place the element behind others with higher or default stacking.
Fix the error in the code to correctly apply z-index.
.box {
position: relative;
z-index: [1];
background-color: red;
}For z-index to work, the element must have a position other than static. The code is missing position. Setting z-index alone has no effect without position.
Fill both blanks to create a stacking context and set z-index.
.modal {
position: [1];
z-index: [2];
}Setting position: fixed; creates a stacking context. A high z-index like 1000 ensures the modal appears above other elements.
Fill all three blanks to correctly layer elements with z-index and position.
.header {
position: [1];
z-index: [2];
}
.footer {
position: relative;
z-index: [3];
}The header uses position: absolute; with a higher z-index: 10; to appear above the footer, which has z-index: 5; and position: relative;.