首页
CSS
CSS Z-index
试用:z-index 示例
运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> .container { position: relative; } .black-box { position: relative; z-index: 1; border: 2px solid black; height: 100px; margin: 30px; } .gray-box { position: absolute; z-index: 3; /* gray box will be above both green and black box */ background: lightgray; height: 60px; width: 70%; left: 50px; top: 50px; } .green-box { position: absolute; z-index: 2; /* green box will be above black box */ background: lightgreen; width: 35%; left: 270px; top: -15px; height: 100px; } </style> </head> <body> <h1>Z-index Example</h1> <p>An element with greater stack order is always above an element with a lower stack order.</p> <div class="container"> <div class="black-box">Black box (z-index: 1)</div> <div class="gray-box">Gray box (z-index: 3)</div> <div class="green-box">Green box (z-index: 2)</div> </div> </body> </html>