Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

父div为fixed,子div为absolute,设置bottom:0,并不生效,如下代

问题

父div为fixed,子div为absolute,设置bottom:0,并不生效,如下代码

在线运行查看

image.png

  <div class='dialog'>
    <div class='dialog-cover-layer'></div>
    <div class="dialog-content">
      <div class="content-top">top</div>
      <ul class='content-middle'>
        <li>...</li>
      </ul>
      <div class='content-bottom'>bottom</div>
    </div>
  </div>
  <style>
    .dialog-cover-layer {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 100%;
      opacity: 0.3;
      background: #000000;
    }

    .dialog-content {
      position: fixed;
      top: 56px;
      bottom: 59px;
      left: 0;
      right: 0;
      z-index: 2;
      width: 500px;
      height: auto;
      margin: 0 auto;
      background: #fff;
      overflow-y: auto;
      padding-top: 50px;
      padding-bottom: 50px;
      box-sizing: border-box;
    }

    .content-top {
      position: absolute;
      left: 0;
      top: 0;
      z-index: 9999;
      width: 100%;
      height: 50px;
      background-color: red;
    }

    .content-bottom {
      position: absolute;
      left: 0;
      bottom: 0;
      z-index: 9999;
      width: 100%;
      height: 50px;
      background-color: blue;
    }
  </style>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

给你

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .dialog-cover-layer {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1;
        width: 100%;
        height: 100%;
        opacity: 0.3;
        background: #000000;
      }
  
      .dialog-content {
        position: fixed;
        top: 56px;
        bottom: 59px;
        left: 0;
        right: 0;
        z-index: 2;
        width: 500px;
        height: auto;
        margin: 0 auto;
        background: #fff;
        overflow-y: auto;
        padding-top: 50px;
        padding-bottom: 50px;
        box-sizing: border-box;
        overflow: hidden;
      }
  
      .content-top {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 9999;
        width: 100%;
        height: 50px;
        background-color: red;
      }
  
      .content-bottom {
        position: absolute;
        left: 0;
        bottom: 0;
        z-index: 9999;
        width: 100%;
        height: 50px;
        background-color: blue;
      }
      ul{
        height: 100%;
        overflow: auto;
        margin: 0;
      }
    </style>
  </head>
  <body>
    <div class='dialog'>
      <div class='dialog-cover-layer'></div>
      <div class="dialog-content">
        <div class="content-top">top</div>
        <ul class='content-middle'>
          <li>..1.</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...</li>
          <li>...100</li>
        </ul>
        <li>...</li>
        <div class='content-bottom'>bottom</div>
      </div>
    </div>
  </body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...