Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the height of a Material-UI's Grid item equals to its width responsively?

I want to make my grid items to be square, e.g. the height of the item equals to is width:

const App = ({ width, items }) => (
  <Grid container>
    {items.map((v) => (
      <Grid item md={width}> // I want to make this Grid to be square
        v
      </Grid>
    ))}
  </Grid>
);

How to do that? note: width is not fixed.

like image 718
Yohei Avatar asked Sep 16 '25 07:09

Yohei


1 Answers

Personally, I would try to use CSS Grid for this layout, but if you want to use the Material UI Grid components, I believe you would have to do something with paddingBottom: '100%' and some tricks with absolute position.

Here's an example: https://codesandbox.io/s/stack-overflow-square-grid-using-mui-cy4p5

like image 90
Robert Cooper Avatar answered Sep 19 '25 03:09

Robert Cooper