0

I understand that in order to use a percentage based height, the parent element must be set to a fixed height? eg 500px.

I am building a grid in which there is a hierarchy of divs. The parent is a fixed height of 500px, and the children are percentage heights, each 33.333%. These children then have a set of children, each which I want to give a percentage height of 100% of it's parent.

Any one know a way around this?

kezey
  • 23
  • 3

1 Answers1

0

Any one know a way around this?

An alternative method is to use flexbox with flex-grow so that children grow to fill their parent

* {margin:0;}
section {
  height: 100vh;
}
section,div {
  display: flex;
  flex-direction: column;
}
div,p {
  flex-grow: 1;
  flex-basis: 0;
}
p {
  background: #eee;
}
div:nth-child(even) p {
  background: #ccc;
}
<section>
  <div>
    <p>text</p>
  </div>
  <div>
    <p>text</p>
  </div>
  <div>
    <p>text</p>
  </div>
</section>
Michael Coker
  • 52,626
  • 5
  • 64
  • 64