1

I am trying to add 100% height to my flex childs. it's not working. I know that i give direction as row but some time i have only 2 child where i need to set 100% height.

Is it possible? if so what is the correct way to do it?

here is my try:

*{
  padding:0;
  margin:0;
}

.parent{
  display:flex;
  height:100%;
  background:lightgray;
  border:1px solid red;
  flex-direction:row;
}

.child1{
  flex:0 0 30%;
  overflow-y: auto;
  background:lightblue;
}
.child2{
  flex:0 0 70%;
  overflow-y: auto;
  background:lightyellow;
}
<div class="parent">
  <div class="child1">child1</div>
  <div class="child2">child2</div>
</div>

Live Demo

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

1 Answers1

1

You have set the parent height as 100%.

You would have to set the height with some absolute unit.

Check below snippet with 100vh

*{
  padding:0;
  margin:0;
}
header{
  height:100px;      
  background:gray;
}
.parent{
  display:flex;
  height:calc(100vh - 65px);
  background:lightgray;
  border:1px solid red;
  flex-direction:row;
}

.child1{
  flex:0 0 30%;
  overflow-y: auto;
  background:lightblue;
}
.child2{
  flex:0 0 70%;
  overflow-y: auto;
  background:lightyellow;
}
<header>
  <h2>Header goes here</h2>
</header>
<div class="parent">
  <div class="child1">child1</div>
  <div class="child2">child2</div>
</div>
Utsav Patel
  • 2,789
  • 1
  • 16
  • 26