Using flexbox could be the solution to the problem, if I have correctly understood the question at hand.
To start, ensure that you explicitly set the margin and padding of all elements to zero, a practice sometimes referred to as bootstrapping. This will override any default styles applied by the browser.
In order to achieve the desired layout, set the height of .screen-emulator
to 100vh
and designate it as the flex container. To maintain the unknown height of .head
, use flex: none;
. The .body
should be set as the sole flex item occupying the remaining available height with flex: 1;
.
https://css-tricks.com/boxes-fill-height-dont-squish/
body,
.screen-emulator,
.head,
.body,
.page,
.page-test {
margin: 0;
padding: 0;
}
.screen-emulator {
width: 300px;
height: 100vh;
background-color: red;
display: flex;
flex-direction: column;
}
.head {
width: 100%;
background-color: blue;
flex: none;
}
.body {
width: 100%;
flex: 1;
overflow-y: auto;
}
.page {
position: relative;
width: 100%;
min-height: 100%;
background-color: black;
}
.page-test {
position: absolute;
width: 100%;
min-height: 100%;
background-color: violet;
}
<div class="screen-emulator">
<div class="head">
<h1>Head</h1>
<p>Random content</p>
</div>
<div class="body">
<div class="page">
<div class="page-test">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Senectus et netus et malesuada fames ac turpis egestas. Massa tincidunt dui ut ornare lectus sit amet. Posuere ac ut consequat
semper viverra nam libero justo laoreet. Sit amet commodo nulla facilisi nullam vehicula ipsum a arcu. Phasellus vestibulum lorem sed risus. Congue eu consequat ac felis donec et odio pellentesque diam. Consectetur lorem donec massa sapien faucibus
</p>
<p>
Nisl suscipit adipiscing bibendum est ultricies integer quis. Pellentesque diam volutpat commodo sed egestas egestas fringilla phasellus faucibus. Netus et malesuada fames ac turpis egestas. Ultricies mi quis hendrerit dolor magna eget. Tellus mauris
a diam maecenas sed enim. Turpis massa tincidunt dui ut ornare lectus sit. Dolor magna eget est lorem ipsum. Sit amet consectetur adipiscing elit ut. Id donec ultrices tincidunt arcu non sodales. Interdum consectetur libero id faucibus nisl
</p>
</div>
</div>
</div>
</div>