Open In App

React Rebass CSS Grid

Last Updated : 10 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads