-5

I have React app that would like to make 20% app bar on top and 80% or the rest of the height fulfill with parent height.

<div>
    //Like to make 20% height
    <div>
        <p>App bar</p>
    </div>
    //Like to make 80% height
    <div>
        <div>Content A</div>
        <div>Content B</div>
        <div>Content C</div>
    </div>
</div>
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Chanrithisak Phok
  • 1,590
  • 1
  • 19
  • 29

2 Answers2

-1

Flex box makes it easiler than ever to scale the dom to fill the rest space.

<div class="parent">
    <div class="app-bar">
        <p>App bar</p>
    </div>
    <div class="rest">
        <div>Content A</div>
        <div>Content B</div>
        <div>Content C</div>
    </div>
</div>

.parent {
  width: 100%;
  height: 100%;
  min-height: 400px;
  display: flex;
  flex-flow: column;
  background-color: #cccccc;
  border: 1 solid #aaaaaa;
}

.app-bar {
  height: 20%;
  background-color: #aaaaaa;
}

.rest {
  flex: 1 1 auto;
  background-color: yellow;
  
}
Pengson
  • 845
  • 5
  • 10
  • @xpcrtsAKARithisak yes, you are right. I added more code like the bg color and border, just want to clarify the boundaries of the different div. Hope someone else like to help. – Pengson Nov 08 '22 at 08:04
-2

One of the solution is to try this:

<div style={{display:"flex", flexDirection:"column"}}>
    <div style={{height: "20vh"}}>
        <p>App bar</p>
    </div>
    <div style={{height: "80vh", border:"1px solid blue"}}>
        <div>Content A</div>
        <div>Content B</div>
        <div>Content C</div>
    </div>
</div>
Chanrithisak Phok
  • 1,590
  • 1
  • 19
  • 29