TBH, maybe the simplest way forward is to wrap the text in <span> tags with a distinct class attribute. Then your CSS can directly target that class regardless of surrounding context.
If that’s an untenable solution, you might be able to target the text with advanced CSS selectors like [attribute=value] or :nth-child(). But to do so, the text needs to be within an element. You cannot target text alone with CSS. So you may need <span> tags even if you can avoid class attributes.
You might instead consider implementing the text as an :after pseudo-element. Then it’ll surely be related to an element and can be styled accordingly.
Thanks for those suggestions @bcworkz.
I was hoping that, just like being able to highlight selected text with a colour via the block’s rich text drop down, there was a similar way to apply my own styling.
If I use my browser’s inspector, selected text that’s been highlighted in that way gets:
<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-medium-pink-color">my screen</mark>
Ideally I’d be able to apply my own class in the same way.
After posting my reply to @bcworkz I got thinking about the classes added when highlighting with the block’s rich text drop-down. This is an example:
<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-bright-blue-color">(opens in a new tab / window)</mark>
In my Customizer, I added a definition of:
.has-bright-blue-color {font-size: smaller;}
to my Additonal CSS and it worked!
Ok, it’s not what I’d call the right way but now I highlight the text, use the block’s rich text drop down, choose A Highlight and then choose the bright blue colour. When I preview and publish, sure enough, that text has the bright blue colour and also has a reduced font size.
So maybe I’ll stick with that approach unless anyone can give me a good reason that it’s not a good idea.