Let's say I have:
<p>Paragraph.</p>
<div class="note">Naked Note Div.</div>
<div class="note">
<p>Paragraph in Note DIV.</p>
<p>Second Paragraph in Note DIV.</p>
</div>
<div>NON Note Naked Div.</div>
<div>
<p>Paragraph in NON None DIV.</p>
</div>
I would then like to get the output:
Paragraph.
NOTE: Naked Note Div.
NOTE: Paragraph in Note DIV.
Second Paragraph in Note DIV.
NON Note Naked Div.
Paragraph in NON None DIV.
I have tried to use pseudo class ::before to achieve this but the fact that some divs have paragraphs inside and some don't makes it surprisingly difficult, at least for newbie me.
With: CSS .note::before {content: "NOTE: ";} I get:
Paragraph.
NOTE: Naked Note Div.
NOTE:
Paragraph in Note DIV.
Second Paragraph in Note DIV.
With CSS .note :first-child::before {content: "NOTE: ";} I get:
Paragraph.
Naked Note Div.
NOTE: Paragraph in Note DIV.
Second Paragraph in Note DIV.
Is there any way to fix this with just CSS? That is not using a preprocessor or jquery or such.
You can try with the
:has()selectorUntil better support for
:has()you can use float: