html - 如何在页面中心的绝对 div 中静态定位绝对 div
问题描述
这是我正在使用的代码笔:https ://codepen.io/marcdaframe/pen/ExajEXK
我希望能够将绿色 div 静态地居中在屏幕的中心,并允许它随着屏幕滚动,但是我不能从这个结构中删除它。
逃避绝对位置父母以允许.abs3 div在屏幕上静态居中的最佳方法是什么
.wrapper{
position: relative;
width: 100vw;
height: 4000px;
display: block;
background-color: black;
}
.abs1{
position: absolute;
background-color: red;
width: 300px;
height: 300px;
}
.abs2{
position: absolute;
background-color: blue;
width: 200px;
height: 200px;
}
.abs3{
position: absolute;
background-color: green;
width: 100px;
height: 100px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%)
}
<div class="wrapper">
<div class="abs1">
<div class="abs2">
<div class="abs3"/>
</div>
</div>
</div>
解决方案
推荐阅读
- javascript - jQuery滚动到元素然后单击它
- scala - 向 Spark 数据框添加其他列
- ios - 在子 ViewController 之间转换期间停止 TabBar 动画
- laravel - 在 laravel InfyOm 中设置随机字符串变量
- elasticsearch - 如何在 Elastic Cloud Enterprise 中拍摄特定索引的快照?
- database - 有什么方法可以参数化 mule 4 中 SQL 查询中提供的表名
- kendo-ui - 剑道日期选择器只选择今天起
- git - Git-垃圾保留时间
- python-3.x - 使用 lambda 在 DynamoDB 中插入项目而不会丢失数据
- android - Android Studio:R.jar:该进程无法访问该文件,因为它正在被另一个进程使用