Consider the following code snippet:
<div class="main-element">
<h4>Title 1</h4>
<ul>
<li></li>
<li></li>
<li>
<h4>Title2</h4>
</li>
</ul>
</div>
The goal is to apply the same styling to all h4 elements, while adding additional styles to the first one. Specifically, the margin-top and margin-bottom for all h4 elements should be 8px, except for the first h4 element which should have a margin-top of 0.
Attempts were made using :first-child and first-of-type selectors, as shown below:
.main-element h4 {
color: blue;
}
.main-element h4:first-of-type {
color: red;
}
However, this resulted in all h4 elements being colored red, rather than just the first one.