With the following, there is a about 20px height gap at the beginning, I know h1 has default margin, and it seems div decides to respect that margin, I’m not sure the reason, I remeber the CSS part of the learn web devlopment does explain margin collposing when two adjacent siblings touchs, but what about parent and child? Another stange thing is, if I add a border to the div, then the gap disappers, it seems it decides no longer to respect the margin of h1, I don’t understand the reason.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<style>
body {
margin: 0;
}
div {
background-color: blue;
color: white;
/* border: 1px solid black; */
}
</style>
</head>
<body>
<div>
<h1>test</h1>
</div>
</body>
</html>