Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

层叠上下文是否会在图层树中以独立图层存在?

浏览器工作原理相关的文章中介绍浏览器渲染进程生成图层树,拥有层叠上下文属性的元素会被提升为单独的一层。
但在浏览器中运行Demo,DevTools Layers中却并没有出现元素分层结果。
Demo代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1, .box2 {
            width: 200px;
            height: 200px;
            position: absolute;
        }
        .box1 {
            background-color: red;
            z-index: 1;
        }
        .box2 {
            background-color: blue;
            z-index: 0;
            left: 100px;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>
</html>

尝试使用position:sticky配合left: 100px,确实会出现分层。
猜想是浏览器不会处理所有层叠上下文?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...