1

My header does not fully covers my page making the background color overlaps them both together.

<!DOCTYPE html>
<html>
<head>
<style>
#header {
    background-color: black;
    background-size: 100% auto;
    margin-left: 0;
    margin-top: 0;
}
</style>
</head>

<body style="background-color: blue;">

        <div id="header">
    <p>hi</p>
    </div>

</body>
</html>
Darren Toh
  • 11
  • 1

4 Answers4

2

This is because browsers have a default margin / padding. //edit HTML default body margin

Add this to your css

html,body{
padding:0;
margin:0;
}
p{
padding:0;
margin:0;
}
Community
  • 1
  • 1
AddcitedToLearn
  • 398
  • 2
  • 18
1

You need to set both html and body height, then #header height, like so

html, body, #header {
  height: 100%;
  margin: 0;
  padding: 0;
}

#header {
  background-color: blue;
}

p{
  margin: 0;
  padding: 0;
}
<div id="header">
<p>
Hi!
</p>
</div>
Mattia Nocerino
  • 1,474
  • 1
  • 16
  • 33
0

enter image description here

If you inspect the html and check the CSS applied to body tag, you will see that it has a default margin: 8px. You will have to make it 0.

Use margin: 0px to set the new margin to body tag.

Charul
  • 450
  • 5
  • 18
-1

Firefox (for example) indicates that there is a "border" of 8. Adding border: 0 to body's style made the thin blue borders to the left and right disappear. Is that what you wanted?

U. Windl
  • 3,480
  • 26
  • 54