I want to make a mobile first responsive layout using flex where three sections are divided vertically in 20:50:30 ratio with full height of screen.
This the HTML part:
<body>
<main>
<div class="parent">
<div class="topSection">
This is Top Section
</div>
<div class="middleSection">
This is Middle Section
</div>
<div class="bottomSection">
This is Bottom Section
</div>
</div>
</main>
</body>
Expected Layout:
Use height: 100vh
to make the parent 100% of the "view height". Set display: flex
on your parent and set the flex-direction: column
.
Then you can use the flex
option on the children to give them the relative size you want.
The whole css should look something like this:
.parent {
height: 100vh;
display: flex;
flex-direction: column;
}
.topSection {
flex: 2;
}
.middleSection {
flex: 5;
}
.bottomSection {
flex:3;
}
I hope this is what you are looking for. Have a great day 🖖