Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky) and flex items.
CSS Tutorial
CSS Tutorial
CSS Advanced
CSS Responsive Layouts
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Stacking
7 min read
•
Chapter 14 of 23
CSS Z-index & Stacking Context
The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order.
Example
<!DOCTYPE html>
<html>
<body style="font-family:sans-serif;padding:20px;">
<div style="position:relative;">
<div style="position:absolute;left:20px;top:20px;width:100px;height:100px;background:#ef4444;z-index:1;">Layer 1</div>
<div style="position:absolute;left:50px;top:50px;width:100px;height:100px;background:#10b981;z-index:2;color:white;padding:8px;">Layer 2 (z-index: 2)</div>
</div>
</body>
</html>
Try it Yourself >>
Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Community Q&A & Discussion
Verified
No questions yet. Be the first to start the discussion!