html - 将元素对齐到 div 容器的底部并在滚动时保持在该位置
问题描述
向下滚动时垃圾桶会向上移动,并且它不会跨越父 div 的整个宽度
我希望它是这样的:
.ParentDiv {
background: red;
overflow-y: scroll;
border: none;
float: left;
position: relative;
height: 80px;
width: 200px;
}
#DivAroundTrashcan{
position:fixed;
bottom: 0;
width: 100%;
height: 15px;
}
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="ParentDiv" id="ParentDiv" >
<p1><center>efgf </center></p1>
<p2><center>wefwf </center></p2>
<p3><center>wefwef </center></p3>
<p4><center>wefwef </center></p4>
<p5><center>wefwef </center></p5>
<p6><center>wefweff </center></p6>
<p7><center>wefwef</center></p7>
<p8><center>wefwef </center></p8>
<div id="DivAroundTrashcan"><input type="button"id="Trashcan"value="🗑"></div>
</div>
</body>
</html>
位置:绝对; 只是让它留在原地,但滚动时它不会留在原地
解决方案
放在position: fixed
垃圾桶的容器div上,而不是绝对的。
推荐阅读
- json - 在 Kotlin/Native 中使用 kotlinx.serialization 进行多态反序列化
- twig - 没有输入的树枝功能/过滤器?
- algorithm - 为什么这个 scala 函数使用映射比使用列表运行得更快?
- kubernetes-helm - 我如何在 kubernetes 上安装盛宴
- javascript - 为什么 React 会重新渲染我未更改的列表项?我怎样才能防止这种情况?
- javascript - 为什么在可用性检查后,MacOS/iOS 设备中的 localStorage 有时会为空?
- python - 生成随机数并添加到新行
- java - Visual Studio Java 语法高亮
- reactjs - React 在 Visual Studio Code 中的编译速度非常慢
- rust - Rust:在编译时从函数创建数组