0

I am facing the problem to align the content div in a data div. The Data div was not fixed height. Because it was auto height when the content div increase.

But it was going to out of flow. How to solve it ?

.container
{
  position:relative;
  border:1px solid blue;
  margin:auto;
  width:200px;
}

.data
{
  position:relative;
  border:1px solid green;
  width:100px;
  top:10px;
  left:10px;
}

.hed
{
  position:absolute;
  border:1px solid orange;
  width:30px;
  height:10px;
  top:-5px;
  left:10px;
  border-radius:5px;
  background-color:orange;
  line-height:10px;
}
<div class="container">
  <div class="data"> This is absolute.</div>
  <div class="hed">xxx</div>
</div>
Teemu Leisti
  • 3,750
  • 2
  • 30
  • 39
user3836476
  • 995
  • 2
  • 9
  • 12

4 Answers4

0

You can set

overflow:hidden;

to the "container" div

Victor
  • 893
  • 1
  • 10
  • 25
0

If you want to have the container expand as the data div expands, add <br style = "clear:both"> before the closing div tag.

FIDDLE

sideroxylon
  • 4,338
  • 1
  • 22
  • 40
0

change all css position to relative and use min-height then try

like this

.container {
    position:relative;
    border:1px solid blue;
    margin:auto;
    width:200px;
    min-height:10px; //added
}
.data {
    position:relative;
    border:1px solid green;
    width:100px;
    top:10px;
    left:10px;
}
.hed {
    position:relative;  //changed
    border:1px solid orange;
    width:30px;
    height:10px;
    top:-50px; //changed
    left:10px;
    border-radius:5px;
    background-color:orange;
    line-height:10px;
}

WORKING DEMO

Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49
0

Why are you using for div class="data":

  • top
  • left

You juste need to replace them by margin-top and margin-left.

.container
{
  position:relative;
  border:1px solid blue;
  margin:auto;
  width:200px;
}

.data
{
  position:relative;
  border:1px solid green;
  width:100px;
  margin-top:10px; // changed
  margin-left:10px; // changed
}

.hed
{
  position:absolute;
  border:1px solid orange;
  width:30px;
  height:10px;
  top:-5px;
  left:10px;
  border-radius:5px;
  background-color:orange;
  line-height:10px;
}
<div class="container">
  <div class="data"> This is absolute.</div>
  <div class="hed">xxx</div>
</div>
Navid EMAD
  • 382
  • 1
  • 15