DEV Community

raboomar
raboomar

Posted on

React CSS Grid

  1. Creating our app
npx create-react-app my-react-grid  
cd my-react-grid
code .
Enter fullscreen mode Exit fullscreen mode
  1. Cleaning up our app: Delete everything in our App.js add four divs: 1) Container 2)header 3)main body 4)footer it should look like this once you're done.
import "./App.css";

function App() {
  return (
    <div className="grid-container">
      <div className="header-container">Header</div>
      <div className="body-container">body</div>
      <div className="footer-container">Footer</div>
    </div>
  );
}

export default App;

Enter fullscreen mode Exit fullscreen mode

Next is cleaning up our app.css:
Delete everything and add the following code:

.grid-container {
  display: grid;
  grid-template-areas:
    "header header header header header header"
    "body body body body body body"
    "footer footer footer footer footer footer";
  gap: 10px;
  padding: 10px;
}

.header-container {
  grid-area: header;
}
.body-container {
  grid-area: body;
  height: 100vh;
}
.footer-container {
  grid-area: footer;
}
Enter fullscreen mode Exit fullscreen mode

The grid template area is where we establish the cells in the grid and assign them names.
grid-area property specifies a grid item's size and location in a grid layout.
Giving the body a height of 100vh allows it to take the maximum height, pushing the header to the top and the footer to the bottom.

Top comments (1)

Collapse
 
thomasbnt profile image
Thomas Bnt

Hello ! Don't hesitate to put colors on your codeblock like this example for have to have a better understanding of your code 😎

console.log('Hello world!');
Enter fullscreen mode Exit fullscreen mode

Example of how to add colors and syntax in codeblocks