首页 > 试题广场 >

根据代码,请问四个 div 标签从上到下的排列顺序(以 cl

[单选题]
根据代码,请问四个 div 标签从上到下的排列顺序(以 class 值代指)是()
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div {
            width: 20px;
            height: 20px;
        }
        .item1 {
            z-index: -10;
            background-color: yellow;
        }
        .item2 {
            position: fixed;
            z-index: 1;
            background-color: red;
            margin-top: 10px;
        }
        .item3 {
            position: fixed;
            z-index: -1;
            background-color: green;
            margin-top: 40px;
        }
        .son {
            position: fixed;
            z-index: 100;
            background-color: black;
            margin-top: 30px;
        }
    </style>
</head>
<body>
    <div class="item1"></div>
    <div class="item2"></div>
    <div class="item3">
        <div class="son"></div>
    </div>
</body>
</html>
  • son、item2、item3、item1
  • item1、item2、item3、son
  • item2、item1、item3、son
  • item1、son、item2、item3
复制到html看了一下,按渲染顺序的话,应该是static的item1最先渲染(在最底部),接下来是z-index: -1;的item3,son由于在item3内部,且z-index: 100,高于3,但是3低于2,因此顺序从低到高是item1,item3,son,item2;但是现在题目问的只是顺序,并且有margin,使得它们并没有重叠起来,而是分散显示,这样的顺序就是 1,2,3,son
发表于 2025-06-25 15:09:28 回复(0)
这道题有大佬解释下吗
发表于 2025-06-20 19:28:14 回复(0)