0

I just started building a webpage using html and made a simple header for it. I want the header to be exactly along the borders of the screen but there is a white space all around my header. This is how it looks: enter image description here

I changed my css by setting the margin, border and outline of my header to 0. But this doesn't seem to do the work and the white space is still there. Here is my code:

<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
    <style type="text/css">
        h1{
            margin:0 auto;
            padding:20px;
            border:0;
            outline:0;
            background: #003399;
            color: #ffffff;
            font-family: "Calibri";
            font-weight: normal;
        }
    </style>
</head>
<body>
    <header>
        <h1>This is my website.</h1>
    </header>
</body>
</html>

I can't figure out what my error is. Please anyone help. Thanks for the attention.

Faiq Irfan
  • 181
  • 1
  • 12

3 Answers3

1

By default body tag take some CSS, just add following css for this

body {
    margin: 0px;
    padding: 0px;
}
Super User
  • 9,448
  • 3
  • 31
  • 47
0

Add this css

body, html {
  margin: 0px;
  padding: 0px;
}
Super User
  • 9,448
  • 3
  • 31
  • 47
LKG
  • 4,152
  • 1
  • 11
  • 21
0

In all my projects I place this code just at the start of my CSS files:

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

So I have more control about margins, paddings and sizes (box-sizing: border-box makes borders and padding being applied inside the container size, not as an extra size, so it's easier to play with percentage sizes).

Another option is to put normalize.css before your styles, that already includes usual corrections like these.

Gerard Reches
  • 3,048
  • 3
  • 28
  • 39