层叠上下文
那么什么是层叠上下文呢?
那么层叠上下文是如何表现的?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>层叠上下文测试</title>
<style>
.con {
position: absolute;
z-index: 1;
}
#root {
position: relative;
background: red;
height: 200px;
width: 200px;
z-index: 3;
}
#sub {
position: absolute;
background: blue;
height: 200px;
width: 200px;
top: 10px;
z-index: 2;
}
</style>
</head>
<body>
<div class='con'>
<div id='root'>root</div>
</div>
<div class='con'>
<div id='sub'>sub</div>
</div>
</body>
</html>这样就创建层叠上下文了?
Last updated