2

Please can you explain to me why body is affected by the margin of its children ? I don't like this behaviour. In my opinion, the margin of a child div should be computed from the boundaries of its parent to its boundaries.

For example : https://jsfiddle.net/2yejm7L5/

You can see that the div in blue affect the margin of body in green, then you see the html background in red and I don't want that.

In my case, I don't want to edit body CSS properties

EntrustName
  • 421
  • 6
  • 19

1 Answers1

0

You will achieve your goal, if you modify the body css to the following:

body {
  background-color: green;
  height: 100%;
  width:100%;
  margin:0;
  position: absolute;
}

/* Another technique */ remove top-margin:50px, and wrap your toto div with another div and give it padding-top:50px; as per below:

html {
  background-color: red;
  height: 100%;
}
body {
  background-color: green;
  height: 100%;
  margin:0;
}

#container { padding-top:50px; }

.toto {
  background-color: blue;
  width: 100px;
  height: 100px;
}
<div id="container">
  <div class="toto">

  </div>
</div>