Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I organise 5 items evenly in a row with material-ui's grid system?

The grid system is 12, how can I evenly put 5 items in a row? 2.4 doesn't work... Thanks in advance :)

my code:

    <Grid container spacing={10}>
        {data.map(item => (
          <Grid item xs={12} md={2.4}>
            <div style={{ fontWeight: "700", textTransform: "capitalize" }}>
              {item}
            </div>
          </Grid>
        ))}
      </Grid>
like image 238
Kiki Avatar asked Apr 23 '20 12:04

Kiki


People also ask

How do you align items in grid material UI?

Material-UI Grid Align Right If you need to horizontally align using only CSS, remember that justify-content horizontally aligns using the following values: flex-start: horizontally aligns left. center: horizontally aligns center. flex-end: horizontally aligns right.

What is grid spacing in material UI?

Material Design margins and columns follow an 8px square baseline grid. The spacing property is an integer between 0 and 10 inclusive. By default, the spacing between two grid items follows a linear function: output(spacing) = spacing * 8px, e.g. spacing={2} creates a 16px wide gap.

What is gutter in material UI?

Gutters — The spaces between the columns are defined by a fixed value at each breakpoint to better adapt the screen size. Margins — The spaces between the left and right sides of the screen are defined by a fixed value similar to gutters, at each breakpoint.


1 Answers

See the Auto Layout section from the docs for an example of how to do this.

For your code, I believe the following should work:

<Grid container spacing={10}>
  {data.map(item => (
    <Grid item xs={12} md>  // should also add a "key" prop here
      <div style={{ fontWeight: "700", textTransform: "capitalize" }}>
        {item}
      </div>
    </Grid>
  ))}
</Grid>
like image 149
sjw Avatar answered Sep 30 '22 15:09

sjw