Search code examples
htmlcssmarginspace

Removing body margin in CSS


I'm new to web development, and met a problem when removing margin of body.

There's space between the very top and "logo" There's space between the very top of the browser and "logo" text. And my code is here on jsbin.

Is body { margin: 0;} wrong if I'd like to remove the space?


Solution

  • I would say that using this global reset is a bad way of solving this.

    * {
      margin: 0;
      padding: 0;
    }
    

    The reason for the h1 margin popping out of the parent is that the parent does not have a padding.

    If you add a padding to the parent element of the h1, the margin will be inside the parent.

    Resetting all paddings and margins to 0 can cause a lot of side effects. Then it's better to remove margin-top for this specific headline.