3


I have simple html document. Is one element into body. When I set margin-top in div element, Chrome add the same margin to body.
Margin is visible only developer tools. My code:

<html>
<body>
<div id="main">Test</div>

<style>
body { background-color: red; }

#main { background-color: blue; margin-top: 100px; }
</style>
</body>
</html>
Krystian
  • 95
  • 1
  • 5

3 Answers3

1

A HTML web document has default css styles, these values are defaulted if you haven't applied any styles of your own. You can override them by applying styles on those particular elements.

for instance, applying the below style, body tag loses its default css style

body{
   margin:0;
}
kotAPI
  • 1,073
  • 2
  • 13
  • 37
0

Set the following style to body tag.

body {
    margin: 0;
    padding: 0;
}

Here is the jsfiddle link.

kmg
  • 499
  • 3
  • 16
0

Your code looking right.(ı tried to change margin block number and it worked)

Any code on the top maybe affect your margin block.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

<div id="main">Test</div>

<style>
body { background-color: red; }

#main { background-color: blue; margin-top: 100px; }
</style>

</body>
</html>
h__g
  • 84
  • 4