首页 > 解决方案 > 将元素对齐到 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="&#128465"></div>
</div>

</body>
</html>

位置:绝对; 只是让它留在原地,但滚动时它不会留在原地

标签: htmlcssalignmentscrollviewscrollbar

解决方案


放在position: fixed垃圾桶的容器div上,而不是绝对的。


推荐阅读