0

strong text

.inside{
position: absolute;
background-color:red;
top:0px;
left:0px;
width:200px;
height: 200px;
}
.inside2{
height: 210px;
background-color: blue;
}
.inside3{
height: 220px;
background-color: black;
}
.box {
  position: relative;
}
<html>

<body>
    <div class="box">
      <div class="inside"></div>
      <div class="inside"></div>
    </div>
  <div class="box">
    <div class="inside inside2"></div>
    <div class="inside inside2"></div>
  </div>
  <div class="box">
    <div class="inside inside3"></div>
    <div class="inside inside3"></div>
  </div>
</body>

</html>

So I have 2 div(inside class) that overlap, its size is unfixed (it maybe 200px or 210px ...). I already make it overlap using positive: absolute and set the box to be relative. The problem with the box is it have 0px height so these boxes just overlap the same position (instead 3 individual box). How to fix it:

enter image description here

What i want: enter image description here

cdxf
  • 5,501
  • 11
  • 50
  • 65

1 Answers1

1

if I understand your problem, then you need to use a combination of display: table-cell for .box and float: left for .inside:

.inside{ width:50px; float: left; }
.inside1 { height: 220px; background-color: red; }
.inside2 { height: 210px; background-color: blue; }
.inside3 {  height: 200px; background-color: black;}
.box { position: relative; display: table-cell; border: 1px solid red; }

<div class="box">
  <div class="inside inside1"></div>
  <div class="inside inside2"></div>
  <div class="inside inside3"></div>
</div>

[ https://jsfiddle.net/2akhf3fo/ ]

stdob--
  • 28,222
  • 5
  • 58
  • 73