score:14
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.
score:1
box
the box component serves as a wrapper component for most of the css utility needs.
the box component wraps your component. it creates a new dom element, a <div>
by default that can be changed with the component property.
let's say you want to use a <span>
instead:
<box component="span" m={1}>
<button />
</box>
this works great when the changes can be isolated to a new dom element. for instance, you can change the margin this way.
grid
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.
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.
further reading
score:2
box
the box component serves as a wrapper component for most of the css utility needs. the box component packages all the style functions that are exposed in @material-ui/system . it's created using the styled() function of @material-ui/core/styles
grid
gridbox is the low-level representation of grid. except for low-level notebook expression manipulation, gridbox should not need to be used directly. in a notebook, columns of a gridbox can be added using and rows using . or a menu item can be used to start building a gridbox.
score:3
use box when you want to group several items and control how they look on the page. for example, you can take several paragraphs and use a box to put a border around them.
use grid for setting up a grid layout system for organizing content in columns on the page. designers will divide the page into 12 columns with the idea that it is more visually appealing to have content aligned along each column or group of columns. here is an article that provides much better detail on the subject: https://www.interaction-design.org/literature/article/the-grid-system-building-a-solid-design-layout
score:19
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>
Source: stackoverflow.com
Related Query
- What is the difference between Box and Grid in Material-UI?
- In Material UI what is the difference between a space after the ampersand and no space?
- What is the difference between React Native and React?
- What is the difference between state and props in React?
- What is the difference between HashRouter and BrowserRouter in React?
- What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So where should we use them?
- What is the difference between redux-thunk and redux-promise?
- What is the difference between componentWillMount and componentDidMount in ReactJS?
- What is the difference between NextJs and Create React App
- What is the difference between jest.fn() and jest.spyOn() methods in jest?
- What is the technical difference between .jsx and .js files
- What is the difference between hashHistory and browserHistory in react router?
- What is the difference between Reactjs and Rxjs?
- What is the difference between .env.local and .env.development.local?
- What is the difference between Jest and enzyme?
- What is the difference between JavaScript and JSX?
- What is the difference between `PropTypes.node` and `PropTypes.any` in react?
- What is the difference between render and return in reactjs?
- What is the difference between Redux Thunk and Redux Saga?
- what is the difference between import and const and which is preferred in commonjs
- What is the difference between @material-ui and @mui
- What is the difference between .js, .tsx and .jsx in React?
- What is the difference between useQuery and useLazyQuery in Apollo graphQL?
- React Native - What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()?
- react-redux: What is the difference between state.setIn() and state.set()?
- In React, what is the difference between onKeyUp and onKeyUpCapture (and onKeyDown/Capture)?
- What is the main difference between using React-Redux Hooks and React-Redux Connect()?
- What is the main difference between React Query and Redux?
- what is the difference between ( )=>React.FC and ( )=>JSX.Element
- what is the difference between React.HTMLProps<> and React.HTMLAttributes<T>?
More Query from same tag
- Rendering / Returning HTML5 Canvas in ReactJS
- How to use react-jss within react class Components?
- Firebase On Value get state react hooks
- How to use Material-UI Autocomplete component to select multiple options and add new options?
- Javascript Math.random() returning very similar values
- Splicing items from an array in a for loop, get typeerror
- CSV generate data format
- I need to handle different inputs onChange methods with one handler
- Laravel-echo showing 401 (Unauthorized) for private channel except one user
- ReactJS : onClick in sub-component does not trigger
- Toolbar mis-placed Navigation Item React
- Mocha & Enzyme - How to test that React component has no children?
- Mounting React-Popup component throws render error
- How do I repeat one image a bunch of times to fill up a page in React JSx?
- Accessing useState value from jest test
- Prevent maxLength on number input from constantly changing value on last number?
- Highlight current date in react Gantt timeline
- Prevent React from re-render partial SSR content on hydrate
- × Error: Too many re-renders. React limits the number of renders to prevent an infinite loop
- How to fix "TypeError: _this is undefined"
- Post request with axios and redux-thunk in a redux-form
- Dynamically Added Dropdown not applying jQuery
- is this method object.keys returning an array or keep it an object
- Show popup with info brought from a table element in react.js
- How to merge objects with empty string values?
- Sharing data between React components
- Render two components from a switch statement react
- uncaught typeerror: this.props.yyy is not a function in react
- React-Bootstrap: Why renders the Alert component the text differently if the text is stored inside a state variable?
- How can I combine onBlur and onFocus in my React Component without reselecting the text on every letter I type in?