主頁
CSS
CSS Z-index
Tryit:不帶 z-index
執行 ❯
建立您
自己的
網站
×
改變方向
儲存程式碼
改變主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> .container { position: relative; } .black-box { position: relative; border: 2px solid black; height: 100px; margin: 30px; } .gray-box { position: absolute; background: lightgray; height: 60px; width: 70%; left: 50px; top: 50px; } .green-box { position: absolute; background: lightgreen; width: 35%; left: 270px; top: -15px; height: 100px; } </style> </head> <body> <h1>Overlapping elements</h1> <p>If two positioned elements overlap each other without a z-index specified, the element defined last in the HTML code will be shown on top:</p> <div class="container"> <div class="black-box">Black box</div> <div class="gray-box">Gray box</div> <div class="green-box">Green box</div> </div> </body> </html>