css 如何使div固定在底部[复制]

sulc1iza  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(151)
    • 此问题在此处已有答案**:

How to keep footer at bottom of screen [duplicate](6个答案)
昨天关门了。
我想使div "菜单"在底部固定,即使滚动有什么办法,我可以做到这一点,请任何帮助

.overflow{
      width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    position: absolute;
    inset: 0px;
    display: block;
}
.menu{
      display: flex;
    flex-direction: column;
    position: relative;
    margin-top: auto;
    background-color: white;
    border-radius: 12px 12px 0px 0px;
    max-height: 90%;
    transform: translateY(0px);
    transition: transform 250ms ease-out 0s;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="overflow">
  </div>
  <div class='menu'>
   <h1>item 1 </h1>
    <h1>item 1 </h1>
  
  </div>
</body>
</html>

我想使div "菜单"在底部固定,即使滚动有什么办法,我可以做到这一点,请任何帮助

nhhxz33t

nhhxz33t1#

menu上的position: relative替换为position: fixed,并将其设置为位于底部的left: 0bottom: 0

.overflow {
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  position: absolute;
  inset: 0px;
  display: block;
  min-height: 2000px;
}
.menu {
  /* 👇 Add these */
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  margin-top: auto;
  background-color: white;
  border-radius: 12px 12px 0px 0px;
  max-height: 90%;
  transform: translateY(0px);
  transition: transform 250ms ease-out 0s;
}
<div class="overflow">
</div>
<div class='menu'>
  <h1>item 1 </h1>
  <h1>item 1 </h1>
</div>

相关问题