Stacking DIVs on top of each other?

前端 未结 9 2264
暗喜
暗喜 2020-12-02 07:59

Is it possible to stack up multiple DIVs like:

&l
相关标签:
9条回答
  • 2020-12-02 08:29

    style="position:absolute"

    0 讨论(0)
  • 2020-12-02 08:33

    Position the outer div however you want, then position the inner divs using absolute. They'll all stack up.

    .inner {
      position: absolute;
    }
    <div class="outer">
       <div class="inner">1</div>
       <div class="inner">2</div>
       <div class="inner">3</div>
       <div class="inner">4</div>
    </div>

    0 讨论(0)
  • 2020-12-02 08:36

    I positioned the divs slightly offset, so that you can see it at work.
    HTML

    <div class="outer">
      <div class="bot">BOT</div>
      <div class="top">TOP</div>
    </div>
    

    CSS

    .outer {
      position: relative;
      margin-top: 20px;
    }
    
    .top {
      position: absolute;
      margin-top: -10px;
      background-color: green;
    }
    
    .bot {
      position: absolute;
      background-color: yellow;
    }
    

    https://codepen.io/anon/pen/EXxKzP

    0 讨论(0)
提交回复
热议问题