I have a web app layout, that consists of navigation bar, side navigation and page content. Unfortunately with current setup, page content container it doesn’t grow with content. https://codesandbox.io/s/friendly-allen-9ycgq4
function App() {
return (
<React.Fragment>
<div style={{ backgroundColor: "blue", height: "3.25rem" }}>
Global navigation
</div>
<div
style={{
display: "flex",
padding: "1rem",
gap: "1rem",
height: "calc(100vh - 3.25rem)",
width: "100%",
maxWidth: "1600px",
overflow: "auto",
boxSizing: "border-box"
}}
>
<div
style={{
width: "15rem",
backgroundColor: "red",
position: "sticky",
top: "0",
}}
>
Side navigation
</div>
<div style={{ flexGrow: "1" }}>
<div style={{ height: "150%", backgroundColor: "green" }}>
Main content
</div>
</div>
</div>
</React.Fragment>
);
}
ReactDOM.render(<App />, document.getElementById("root"));
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<div id="root"></div>
Is there a way to make this component with flex-grow: 1 have full height of it’s children, not only screen size?
The reason I’m asking is because when i have this height of 150%
, when i scroll down, padding of 1rem
is not visible.
2
Answers
EDIT: I think I now get what you wanted to do Codesandbox
You also need to set
height: 100%
onhtml, body, #root, .App
The code rearranges the layout components to ensure the side navigation appears first, followed by the main content. The global navigation bar is nested within the main content area. The side navigation is styled with a red background and fixed width. The main content area expands dynamically, and both the main content and side navigation are part of a flex layout.