I am having a hard time getting my .panel_right
to be scrollable without hardcoding a px
value inside the calc
to account for the .navbar
height. Currently this HTML creates two scrollbars. The HTML is being sideloaded/injected into a website with this .navbar
already in it. I did not define or have access to the navbar, so I cannot assume it’s height as it may change in the future.
I do not want to have any calcs
to account for the navbar.
.navbar {
display: flex;
height:50px; /* Assume fixed, external from our code, and it can change */
background-color: red;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
background-color: blue;
}
.panel_top {
background-color: grey;
width: 100%;
height: 30px;
}
.panel_right {
width: 100px;
background-color: green;
max-height: calc(100vh - 30px); /* remaining height after panel_top */
overflow-y: scroll;
}
<body style="width: 100vw; height: 100vh; margin:0;padding:0">
<div class="navbar">
<li>navbar item</li>
<li>navbar item</li>
<li>navbar item</li>
</div>
<div style="container">
<div class="panel_top">panel_top</div>
<div style="min-height: 0;">
<div class="panel_right">
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
<h1>panel_right</h1>
</div>
</div>
</div>
2
Answers
If you gradually push away from the flexible
body
, then everything will work out: