Removing Margin Around an HTML Header
When displaying a header element, some users encounter unnecessary space above it. To address this issue, we can leverage the following CSS code:
body { margin: 0px; padding: 0px; } header { margin: 0px; padding: 0px; height: 20em; background-color: #C0C0C0; } h1 { margin-top: 0; }
This adjustment targets the
The initial issue stemmed from a phenomenon known as margin collapsing. In CSS, when two elements with margins overlap, the resulting margin is equal to the larger of the two margins. This means that in the provided HTML and CSS code, the margin around the header element was collapsing with the margin around the
The above is the detailed content of How to Remove Extra Space Above an HTML Header?. For more information, please follow other related articles on the PHP Chinese website!