I am trying to select only the Random unattached paragraph.
I've tried a number of things that I think should all work (see below or the
<h2 class="important">Hi again</h2>
<p class="a">Random unattached paragraph</p>
There are many ways. You need to decide the semantic meaning of what you want to select and devise your selector based on that.
body > p.awould select all
p.aelements that are direct children of the body tag (i.e., not nested inside any containers).
.important + p.awould select any
p.aelements that come immediately after an
p.a:nth-of-type(1)would select the first paragraph tag if it has class
p.awould select all
p.aelements, and you could then use
.relevant p.ato override (or undo) any attributes on the ones you didn't want to affect.
Well-written semantic HTML should always describe the purpose of an element based on context, tag choice, and class and/or id attributes. If your document's markup is not semantic, there is only so much you can do to create a generalized CSS selector for the components you want to affect.