I am using CSS to set the style for two sibling DIVs (a div.header
and a div.body
) so that their width is equal and the minimum width of the header is the minimum width of its div.wrapper
so that scrollbars will appear on the browser window when narrower than the header.
BUT I am also trying to have scrollbars appear on div.body
when the div.content
within it expands outside of div.body
. Currently the div.body
expands to fit its content. I would also like div.body
to fill the vertical space when div.content
is small.
Edit: It's difficult to explain, so here is a picture that might help. Left side is when the full .header
width is visible. Right side adds scrollbars at the outer level (browser window) when narrower than the .header
text.
I am not confident that my current approach is on the right path, but I have the header enforcing the minimum width based on https://stackoverflow.com/a/48226415
.content {
background-color: pink;
margin: 1rem;
width: 100px;
}
body {
margin: 0;
}
.root {
background-color: yellow;
position: absolute;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
overflow-x: auto;
overflow-y: hidden;
}
.wrapper {
background-color: lightgray;
overflow: hidden;
display: inline-block;
min-width: 100%;
min-height: 100%;
}
.header {
background-color: lightgreen;
white-space: nowrap;
}
.body {
background-color: lightblue;
display: flex;
flex-grow: 1;
overflow-x: scroll;
overflow-y: auto;
}
<div class="root">
<div class="wrapper">
<div class="header">
header header header header header header header header header header header header
</div>
<div class="body">
<div class="content">
content
</div>
</div>
</div>
</div>
Here is my JSFiddle with comments in the .content
style at the top of the CSS.