user2892804
user2892804

Reputation: 143

Make two grid items for Material-UI both same height with Flex-box

I have two grid items that I want to make the same height by trying to use flex, however nothing seems to work. I believe I might now be using the Grid element in Material UI correctly. I have tried using the height and width properties as well.

  <Paper elevation={10} style={{padding:'1.5em'}}>

      <Grid container direction='row' spacing={2} style={{display:'flex'}}>

          <Grid item style={{height:'100%', width:'50%'}}>
          </Grid>

          <Grid item style={{height:'100%', width:'50%'}}>
          </Grid>

      </Grid>

  </Paper>

Upvotes: 7

Views: 15052

Answers (2)

Mehdi Yeganeh
Mehdi Yeganeh

Reputation: 2129

In material ui you can use alignItems="stretch" on the container Grid as you can see in the below code:

<Paper elevation={10} style={{padding:'1.5em'}}>
    <Grid container direction='row' spacing={2} alignItems="stretch">

        <Grid item style={{height:'100%', width:'50%'}}>
        </Grid>

        <Grid item style={{height:'100%', width:'50%'}}>
        </Grid>

    </Grid>
</Paper>

And you didn't need to set style={{display:'flex'}} because of grid style set it too.

References:

Upvotes: 5

Oliver
Oliver

Reputation: 3148

If you are using flex on the parent element, you can try setting align-items: stretch on the parent too. This should stretch all children of that element to be the same height. E.g.

.container {
  display: flex;
  align-items: stretch;
}

Upvotes: 2

Related Questions