800. Styling
- Different options to styling
- Global styles
- Component styles
- SASS or SCSS
- nextjs by default supports SASS, all you need to do is install the library
- sass-support
- SASS-support video
- CSS-in-JS
Global Styles
- by default defined in
styles->global.css
- global styles must be imported in
_app.js
to work
- global styles must be imported in
import '../styles/globals.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
Component Level Styles
- styles that only apply to components and won't conflict with one another
- usually named
component.module.css
.
.highlighted{
border-bottom: 2px solid yellow;
}
import styles from '../styles/about.module.css';
function About() {
return <h2 className={styles.highlighted}>About us page here</h2>
}
export default About;
CSS-in-JS
- inline styles
function About(){
return <h2 style={{color: 'red'}}>Hello this is ... </h2>
}
export default About;
- More popular options
- Nextjs css-in-js ex: styles-components