This is due to collapse.
The upper and lower fields of blocks are sometimes combined (collapsed) into one edge, the size of which is the largest of the fields combined into it, a behavior known as collapse.
Further information can also be found on the w3c website .
Two fields are adjacent if and only if there are no [...] cells, no gaps, no laying , and no border separates them [...]
So, if you apply padding-top ( 1px enough), as in the second example, the fields will no longer collapse. An easy solution, as already suggested, is to remove the default margin of your header elements.
source share