首页 > z-index失效问题

z-index失效问题

我试着写了如下一段代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Review</title>
    <link rel="stylesheet" type="text/css" href="styles/main.css"/>
</head>
<body>
<div class="div1">
    <div class="div2"></div>
</div>
<div class="div3">
    <div class="div4"></div>
</div>
</body>
</html>

main.css

* {
    margin: 0;
    padding: 0;
}

.div1 {
    width: 400px;
    height: 400px;
    margin: 400px auto;
    background-color: red;
    position: relative;
    z-index: 2;
}

.div2 {
    width: 300px;
    height: 300px;
    background-color: green;
    position: absolute;
    left: 50px;
    top: 50px;
}

.div3 {
    width: 200px;
    height: 200px;
    background-color: yellow;
    position: relative;
    top: -700px;
    left: -400px;
    z-index: 3;
}

.div4 {
    width: 100px;
    height: 100px;
    background-color: #ccc;
    position: absolute;
    left: 50px;
    top: 50px;
}

我看不到div3div4,说明了z-index并没有起作用。这是怎么回事?求大神帮忙看看!


.div3 {
    width: 200px;
    height: 200px;
    background-color: yellow;
    position: relative;
    ***top: -700px;
    left: -400px;***
    z-index: 3;
}

这个超出了,改小一点应该就看得到了。
【热门文章】
【热门文章】