is there any way to select a CSS-element that is the first child of its parent, counting text nodes? I want to remove the top margin of a heading if it is at the top of its parent, but if I use:
#content h1 {
margin-top: 1em;
}
#content h1:first-child {
margin-top: 0;
}
and have some HTML like
<div id="content">
This is some text.
<h1>A heading</h1>
Some more text.
</div>
the margin is still removed. Is there any way in CSS to prevent this?
Remove the margin
, not just the margin-top
, h1 element is pushing the next element down
#content h1 {
margin-top: 1em;
}
#content h1:first-child {
margin: 0px;
}
If you want to remove all except first
#content h1:not(:first-child) {
margin: 0px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With