I'm starting with css and html. Trying to do some things I have found a behavior that I can not explain. The body element should be covering the entire html element because the html padding is 0. However, by adding an upper margin of 150px to the <p>
element, the body separates from the html element and distances itself from above.
What I do not understand is why the margin of the element <p>
is distanced from above. I would like the <p>
element to be 150px separate from the body, but the body was not separated above the html those 150px. If I put in <html>
padding: 0, and in <body>
margin: 0, this would have to result that the body is completely stuck on top, just as it is on the sides.
What explanation does this behavior have?
Greetings
<style>
html {padding :0px;
background-color: red;
}
body {
margin:0;
background-color: green;
}
p{ margin : 150px auto;
border: solid ;
background-color: yellow;
height: 250px;
width: 400px;
}
</style>
</head>
<body>
<p> 1</p>
<p> 2</p>
<p> 3</p>
<p> 4</p>
<p> 5</p>
<p> 6</p>
</body>