2

I'm using next.js and created this project using

yarn create next-app

And below is the bare minimum code. I don't know why

h1, h2, h3, h4, h5, h6, p all tags are having default margin top in next.js

index.js

import React, { Component } from "react";
import styles from "../styles/Index.module.css";

export default class index extends Component {
  render() {
    return (
      <div className={styles.container}>
        <h1>Hello world</h1>
      </div>
    );
  }
}

Index.module.css

.container{
    background-color: aqua;
    min-height:100vh;
    width:100%;
}

global.css

html,
body {
  padding: 0px;
  margin: 0px;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

* {
  box-sizing: border-box;
}


unnecessary top margin

Hemendra Khatik
  • 371
  • 4
  • 22

1 Answers1

0

It's due to a margin collapse issue. You can read more about it here. To avoid it you can use the css padding property.

EDIT

You can use the padding property in place of the margin property like so:

h1 {
    padding-top: 20px
}
nad
  • 1,068
  • 6
  • 16