4

I have one div-container and children inside it.

<div id="parent">
    <div class="child"></div>
    <div class="child"></div> 
    <div class="child"></div>
    <div class="child" id="last-child"></div>      
</div>

I don't know height of children (every time different content), but i have

#parent {
   min-height: 500px;
}

I want to stretch last-child to the bottom of parent (it has to fill free space from his subling to parent bottom).

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
MaruniakS
  • 145
  • 1
  • 12

2 Answers2

3

Make the parent a flex box with display:flex; and the flex--direction being column. Next give the last child element the flex:1; property to make it expand to the remainder of the space in the parent.

#parent {
   min-height: 500px;
  display:flex;
  flex-direction: column;
  
}
#last-child{
  flex:1;
  background:blue;
}
.child{
  background:red;  
}
<div id="parent">
    <div class="child">jljlkj</div>
    <div class="child">kjljlkjl</div> 
    <div class="child">kljlkjlhi</div>
    <div class="child" id="last-child"></div>      
</div>
Wowsk
  • 3,637
  • 2
  • 18
  • 29
3

You can use flexbox for this (background colors added for visibility):

#parent {
  min-height: 500px;
  display: flex;
  flex-direction: column;
  background: #999;
}
.child {
  background: #eee;
}
#last-child {
  flex-grow: 1;
  background: #faa;
}
<div id="parent">
  <div class="child">1</div>
  <div class="child">2</div>
  <div class="child">3</div>
  <div class="child" id="last-child">4</div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272