Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Box and Grid in Material-UI?

Tags:

What is the difference between Box and Grid in Material-UI

When to use each one

I'm confused by that

like image 776
Yoel Avatar asked Jul 05 '20 18:07

Yoel


People also ask

What is a grid in material UI?

The Material Design responsive layout grid adapts to screen size and orientation, ensuring consistency across layouts. The grid creates visual consistency between layouts while allowing flexibility across a wide variety of designs. Material Design's responsive UI is based on a 12-column grid layout. Feedback.

What is grid container and item?

A grid container contains grid items. By default, a container has one grid item for each column, in each row, but you can style the grid items so that they will span multiple columns and/or rows.


2 Answers

The grid creates visual consistency between layouts while allowing flexibility across a wide variety of designs. Material Design’s responsive UI is based on a 12-column grid layout.

How it works

The grid system is implemented with the Grid component:

It uses CSS’s Flexible Box module for high flexibility. There are two types of layout: containers and items. Item widths are set in percentages, so they’re always fluid and sized relative to their parent element. Items have padding to create the spacing between individual items. There are five grid breakpoints: xs, sm, md, lg, and xl.

A Box is just that, a box. It's an element wrapped around its content which by itself contains no styling rules nor has any default effects on the visual output. But it's a place to put styling rules as needed. It doesn't offer any real functionality, just a placeholder for controlling the styles in the hierarchical markup structure.

I often think of it as semantically similar to the JSX empty element:

<>     Some elements here </> 

But just with some Material UI capabilities:

 <Box component="span" m={1}>      <Button />  </Box> 
like image 93
Sohail Shahzad Avatar answered Nov 01 '22 04:11

Sohail Shahzad


In short:

Box is a more powerful, convenient, and potential replacement for div. You can change it to any HTML elements (e.g. span), but most of the time you will use it as div replacement.

Grid is the syntactic sugar of Grid Layout.

like image 29
Matthew Kwong Avatar answered Nov 01 '22 03:11

Matthew Kwong