It's baffling to me that the H1 and H2 elements don't align evenly on the left when I add margin-left to them. This has never been an issue for me before.
Check out the code with the problem:
* {
margin: 0;
padding: 0;
}
div h1,
h2 {
margin-left: 1em;
}
<div>
<h1>Inspector Clouseau</h1>
<h2>Reporting for duty</h2>
</div>
Surprisingly, when I apply margin-left to the div tag, they align perfectly as expected. Here's the correct code:
* {
margin: 0;
padding: 0;
}
div {
margin-left: 1em;
}
<div>
<h1>Inspector Clouseau</h1>
<h2>Reporting for duty</h2>
</div>
I just can't wrap my head around why this discrepancy exists.