Reputation: 11
I want to apply .special class selector to a three h2 elements.
.special {
font-style: italic;
}
<h2 class="special">Help Please</h2>
<h2>Can we apply from one CSS rule to many h2 elements?</h2>
<h2>You help will be appreciated</h2>
Upvotes: 0
Views: 1197
Reputation: 7217
You can try like this: Demo
HTML:
<div class="special">
<h2>Help Please</h2>
<h2>Can we apply from one CSS rule to many h2 elements?</h2>
<h2>You help will be appreciated</h2>
</div>
<hr/>
<h2>Help Please normal h2</h2>
CSS:
.special h2 {
font-style: italic;
}
Upvotes: 0
Reputation: 71170
Yes, simply add the class attribute to all three
.special {
font-style: italic;
}
<h2 class="special">Help Please</h2>
<h2 class="special">Can we apply from one CSS rule to many h2 elements?</h2>
<h2 class="special">You help will be appreciated</h2>
Alternatively, to select the first three h2
elements within a parent, use:
h2:nth-of-type(-n+3){
font-style: italic;
}
Or, to style all h2
elements, use:
h2{
font-style: italic;
}
Upvotes: 2