Reputation: 375
I am learning React and using Next js as a framework.
My project structure simply follow the tutorial and using next-sass with next.config.js
//-- next.config.js
module.exports = withSass({
sassLoaderOptions: {
includePaths: ["absolute/path/a", "absolute/path/b"]
}
})
What I want is to remove the default margin on all corners of the page. Suppose I want to cover the whole page with #F5F5F5. How can I achieve this?
Upvotes: 2
Views: 2576
Reputation: 19762
You'll want to do two things:
.scss
into each page. (important: read the note in the link above about defining getInitialProps
within the _app.js
file).scss
file that targets the body
element. By default, it has a margin: 8px;
style applied to it -- you'll want to override this. Then import
this .scss
file into the _app.js
file.Working codesandbox:
pages/_app.js
import React from "react";
import App from "next/app";
import Head from "next/head";
import "../styles/index.scss";
class MyApp extends App {
// remove this 'getInitialProps' if you don't plan on render blocking
// for example, signing a user in before the requested page is loaded
static async getInitialProps({ Component, ctx }) {
return {
pageProps: {
...(Component.getInitialProps
? await Component.getInitialProps(ctx)
: {})
}
};
}
render() {
const { Component, pageProps } = this.props;
return (
<>
<Head>
<link rel="icon" href="/favicon.ico" />
</Head>
<Component {...pageProps} />
</>
);
}
}
export default MyApp;
styles/index.scss
$foreground: #007ec5;
$background: #ebebeb;
body {
background: $background;
color: $foreground;
padding: 20px;
margin: 0;
min-height: 100vh;
}
Upvotes: 2