• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

CSS Selector - Immediate child?

Carson Dyle

Diamond Member
I'm trying to style something where I need to select only the first child when it immediately follows a particular tag of a certain class. The :first-child selector by itself isn't enough. Is there some other way?

I want to select this <b> tag, which is a child that immediately follows a <div> of class message.
Code:
<div class="message">
  <b>I want to select this.</b> Some other text and <b>not this</b> and etc.
</div>

but not select this <b> tag:
Code:
<div class="message">
  Text in which <b>this should not be selected</b> and more and more text.
</div>

(I have no control over the source, so there's no option to rewrite it.)
 
Last edited:
I'm pretty sure that is not possible through pure css. That is pretty simple if you can use javascript for this though.
 
Yeah you can't distinguish whether there is content before the 1st child element or not with css, that would require server-side or javascript.
 
Back
Top