After creating your basic react app and setting up a styled component it's nice to be able to control the css from "inside" your main component. This is how:
- Open the file `src/App.css
- Replace the content with this css
body,
html {
width: 100%;
margin: 0;
background-color: #222;
color: #fff;
}
html,
body,
#root {
height: 100%;
}
- The colors are of course not necessary but helpful to illustrate the point. The page is now covering the full width and height of the screen.
- Go to your App.js component and add a new styled component inside wrapping your components, for clarity we can call it "Page". The code inside App.js should look like this:
import "./App.css";
import MyFirstComponent from "./components/MyFirstComponent";
import styled from "styled-components";
const Page = styled.div`
width: 100vw;
height: 100%;
min-height: 100%;
box-sizing: border-box;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
padding: 2rem;
`;
function App() {
return (
<Page>
<MyFirstComponent />
</Page>
);
}
export default App;
- And that's it!
Thank you!