Z-index basics
📖 Scenario: You are creating a simple webpage with two overlapping colored boxes. You want to control which box appears on top using the z-index property.
🎯 Goal: Build a CSS snippet that sets up two overlapping boxes and uses z-index to control their stacking order so that the red box appears above the blue box.
📋 What You'll Learn
Create two boxes with class names
.box1 and .box2Set the position property to
relative for both boxesSet the background colors:
.box1 to blue and .box2 to redUse
z-index to make sure the red box (.box2) appears above the blue box (.box1)Set the size of each box to 100px by 100px and position them so they overlap
💡 Why This Matters
🌍 Real World
Web designers often need to control which elements appear on top when they overlap, such as menus, modals, or images.
💼 Career
Understanding z-index is essential for front-end developers and UI designers to create visually correct and user-friendly web pages.
Progress0 / 4 steps