Skip to content
Related Articles

Related Articles

React Rebass CSS Grid

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Feb, 2022
View Discussion
Improve Article
Save Article

React Rebass is a front-end framework that was designed keeping react in mind. In this article, we will know how to use CSS Grid in React rebass. CSS Grid is an important component that is required in each development.

CSS Grid is useful for arranging direct child elements without having to apply additional styles to them. Create a Box component extender that wraps other elements to apply a grid layout.

Syntax:

<Box sx={{ display:'grid', gridGap: 4 }}> CSS Grid</Box>

Creating React Application & Installing Module:

Step 1: Create a React application using the following command.

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command.

cd foldername

Step 3: Install React Rebass in your given directory.

npm i rebass

Project Structure: It will look like the following.

Step to Run Application: Run the application from the root directory of the project, using the following command.

npm start

Example 1: This is the basic example that shows how to use the CSS Grid.

App.js




import React from "react";
import { Box, Heading, Text } from "rebass";
  
const gfg = () => {
  return (
    <div id='gfg'>
      <h2>GeeksforGeeks</h2>
      <h4>React Rebass CSS Grid</h4>
      <Box
        sx={{
          display: 'grid',
          gridGap: 4,
        }}>
        <Heading p={3} color='red' bg='green'>
           Grid
        </Heading>
        <Text p={3} color='white' bg='blue'>
           GeeksforGeeks
        </Text>
      </Box>
    </div>
  );
};
  
export default gfg;


Output:

React Rebass CSS Grid

Example 2: In this example, we will know how to make a column-based grid.

App.js




import React from "react";
import { Box, Heading, Text } from "rebass";
  
const gfg = () => {
  return (
    <div id='gfg'>
      <h2>GeeksforGeeks</h2>
      <h4>React Rebass CSS Grid</h4>
      <Box
        sx={{
          display: 'grid',
          gridGap: 4,
          gridTemplateColumns: 'repeat(auto-fit, minmax(128px, 1fr))',
        }}>
        <Heading p={3} color='red' bg='green'>
          Grid
        </Heading>
        <Text p={3} color='white' bg='blue'>
          GeeksforGeeks
        </Text>
      </Box>
    </div>
  );
};
  
export default gfg;


Output:

React Rebass CSS Grid

Reference: https://rebassjs.org/guides/css-grid


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!