咨询一个CSS层定位的问题?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style type="text/css">
.container {
position: relative;
}
.nobox {
width: 100px;
height: 100px;
background-color: green;
}
.box {
position: absolute;
width: 100px;
height: 100px;
background-color: red;
}
.boxs {
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
<div class="container">
<div class="nobox">Box 0</div>
<div class="box">Box 1</div>
<div class="boxs">Box 2</div>
</div>
</body>
</html>
Box 2跑到Box 1下面去了,我需要的是Box 2在Box 1下面的地方,而不是被其遮挡?
回复
1个回答

test
2024-06-19
好想看没啥好办法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style type="text/css">
.container {
position: relative;
}
.nobox {
width: 100px;
height: 100px;
background-color: green;
}
.box {
position: absolute;
width: 100px;
height: 100px;
background-color: red;
}
.boxs {
position: absolute;
top: 100px;
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
<div class="container">
<div class="nobox">Box 0</div>
<div class="box">Box 1
<div class="boxs">Box 2</div>
</div>
</div>
</body>
</html>
这样符合你的要求不
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容