【问题标题】:How to make div fixed in the bottom如何让div固定在底部
【发布时间】:2023-01-21 03:42:02
【问题描述】:

我想在底部固定 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“菜单”,即使滚动有任何方法我可以做到,请帮忙

【问题讨论】:

    标签: html css


    【解决方案1】:

    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>

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多