What you say does not make much sense for the following reasons:
- When doing the absolute left or fixed part, the father's body will not grow .
- If you make the right part fixed then using flexbox is meaningless because it will not apply if you have
position: fixed
.
What you want you can do it in two ways:
Giving a fixed position to the div on the right.
Giving a height of 100% of the view height AND a overflow: auto
to the div of the content.
Both will result in the same, but the second option is cleaner.
Marked
<section class="parent">
<section class="child">
<div class="content">A</div>
</section>
<section class="child">
<div class="content">B</div>
</section>
</section>
Option # 1
*, *:before, *:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.parent {
overflow: auto;
max-height: 100vh;
}
.child:first-of-type {
background-color: gold;
overflow: auto;
width: 50%;
}
.child:last-of-type {
background-color: teal;
height: 100%;
position: fixed;
right: 1.6%;
top: 0;
width: 50%;
}
.content {
background-color: coral;
color: #fff;
display: flex;
font-family: 'segoe ui';
font-size: 48pt;
font-weight: lighter;
height: 1500px;
justify-content: center;
margin: 0px auto;
width: 100px;
}
We see how the right div we have given right: 1.6%
. This is necessary otherwise, will cover the scrollbar . You can set it to 0 and see it for yourself.
Option # 2
*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.parent {
display: flex;
height: 100vh;
overflow: hidden;
}
.child {
flex: 1;
}
.child:first-of-type {
background-color: gold;
overflow: auto;
}
.child:last-of-type {
background-color: teal;
}
.content {
background-color: coral;
color: #fff;
display: flex;
font-family: 'segoe ui';
font-size: 48pt;
font-weight: lighter;
height: 1500px;
justify-content: center;
margin: 0px auto;
width: 100px;
}
This solution is the cleanest. We do not need to use position: fixed
. Only the father must have 100% of the view height and the left div, same, but making it scrollable with overflow: scroll
.
Demos