You can't affect just the :text
without using a <span>
or some other way to mark the text you want to style, but you can approximate it by using the ::first-line
pseudo-selector. This would work for cases where your list items don't span multiple lines.
You also don't need to put a class on every list item; you can put a class on the list itself and use that to target the styling. I added class="subjects"
to the <ol>
for that.
I also removed the <br>
line breaks; you can and should use margin
to create space in-between elements. This is done with the .subjects li
rule.
The main rule to get the gold-on-gray style you want is by targeting the "first-line" in all list items within a .subjects
ordered (or unordered) list, using the selector .subjects li::first-line
.subjects li {
margin-bottom: 0.8em;
}
.subjects li::first-line {
color: gold;
background: gray;
}
<h2>Some Subjects</h2>
<ol class="subjects">
<li>Physics</li>
<li>Astronomy</li>
<li>Mathematics</li>
</ol>