Reputation: 684
I have two div elements inside a Parent div element with class names .variableHT
, .remaining
. Here is the html
<div class="parent">
<div class="variableHT">1234</div>
<div class="remaining"></div>
</div>
and here is CSS
.parent{
height:300px;
}
.variableHT{
height:auto;
background-color:green;
}
.remaining{
margin-top:auto;
margin-bottom:0px;
background-color:yellow;
}
I am trying to make two DIVs, first one is auto height element, height is not fixed, it will grow as per the content size. Then next DIV should occupy whatever the space is remaining. Tried adding margin values but did not workout.
Please help me on this. Here is the fiddle http://jsfiddle.net/GyULa/1/
Upvotes: 1
Views: 53
Reputation: 2175
Try adding height: 100%
to the variableHT
:
.parent{
height:300px;
overflow:hidden;
}
.variableHT{
height:auto;
background-color:green;
}
.remaining{
height: 100%
background-color:yellow;
}
Upvotes: 2
Reputation: 1258
How about this one:
.parent{
display: table;
height: 300px;
width: 100%;
}
.variableHT{
height: auto;
display: table-row;
background-color: green;
}
.remaining{
height: 100%;
display: table-cell;
background-color: yellow;
}
Here is fiddle link for it
Upvotes: 4
Reputation: 17368
First dirty fix...with "overflow:hidden" ;) But interesting question! Is there a more elegant way?
.parent{
height:300px;
overflow: hidden;
}
.variableHT{
height:auto;
background-color:green;
}
.remaining{
margin-top:auto;
margin-bottom:0px;
background-color:yellow;
height: 100%;
}
Upvotes: 2
Reputation: 5795
With overflow:hidden on .parent
and a height specification on .remaining
it works:
.parent{
height:300px;
overflow: hidden;
}
.variableHT{
height:auto;
background-color:green;
}
.remaining{
margin-top:auto;
margin-bottom:0px;
background-color:yellow;
height: 300px;
}
Upvotes: 2