To center both horizontally and vertically to the viewport, one needs to make the <html>
, <body>
, and <div id="root">
fill the viewport. To do this, create a file style.css
:
html,
body,
#root {
height: 100vh;
}
and then import the styles anywhere in your React project. For example, import it in index.js
:
import React from "react";
import ReactDOM from "react-dom";
import SpacingGrid from './SpacingGrid';
import "./style.css"; // Add this!
ReactDOM.render(
<React.StrictMode>
<SpacingGrid />
</React.StrictMode>,
document.getElementById("root")
);
Here is a live version on stackblitz
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…