Home.jsx
<Box component="fieldset" sx={{borderRadius:2, height:"100%"}}>
App.jsx
<Grid container>
<Grid item xs={4} >
<Root/>
</Grid>
<Grid item xs={8} >
<BrowserRouter>
<Routes>
<Route path='/' element={<Home/>}/>
</Routes>
</BrowserRouter>
</Grid>
</Grid>
I’ve put "height:100%" in the Box in Home.jsx because otherwise box is really small cuz there is not much content. I thought this will stretch the height of a box to the height of the Grid, but it goes a little bit over. I can of course play with Home.jsx Box height but obviously I don’t wanna do that, especially cuz there will be more Boxes from different pages.How can I make it so it just fills out the Grid height? Thanks
2
Answers
First things first
There are many ways to solve this issue.
The first one would be to create properly aligned elements, which without seeing the completeness of the code it is hard to reproduce.
The workaround
An improper but effective alternative could be to measure both element’s heights and assign the highest value to both of them.
This post explains how.
Basically, you attach a ref to each element, and using useLayoutEffect you measure them and update the ref.current.clientHeight.
Add the CSS property
box-sizing
with a value ofborder-box
to yourBox
(fieldset
) component.For example:
Which produces:
Working CodeSandbox: https://codesandbox.io/s/box-sizing-njgzc4?file=/demo.tsx