Complete the code to set the stacking order of the element.
.box {
position: relative;
z-index: [1];
}The z-index property controls the stacking order of positioned elements. A higher number means the element appears on top.
Complete the code to make the element positioned so z-index works.
.overlay {
[1]: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}The position property must be set to absolute, relative, or fixed for z-index to work.
Fix the error in the code to ensure the red box appears above the blue box.
.red-box {
position: relative;
z-index: [1];
background-color: red;
width: 100px;
height: 100px;
}
.blue-box {
position: relative;
z-index: 5;
background-color: blue;
width: 100px;
height: 100px;
margin-top: -50px;
}The red box needs a higher z-index than the blue box (which is 5) to appear on top.
Fill both blanks to fix layering so the modal appears above the background and the button stays below the modal.
.background {
position: relative;
z-index: [1];
}
.modal {
position: fixed;
z-index: [2];
background-color: white;
width: 300px;
height: 200px;
}The background should have a lower z-index (like 1) and the modal a higher one (like 10) to appear on top.
Fill all three blanks to create a stacking context where the child is above the parent and sibling elements.
.parent {
position: relative;
z-index: [1];
}
.child {
position: absolute;
z-index: [2];
}
.sibling {
position: relative;
z-index: [3];
}The parent has z-index 1, the child has a higher z-index 10 to appear above, and the sibling has 0 which is below parent but child is above both.