CSS Replace
- 2 minutes read - 299 wordsYou can do quite a lot with CSS, it seems.
A little-known but true fact is that I maintain Pink Goddess’s salon web site. As part of that, we like to play with the “PINK” logoword, kind of how Google does doodles. I will sometimes replace the “I” with something else. For instance, for Valentine’s day, it might show up as “P🩷NK”. And for ages i’d been hacking around with the HTML to do that.
It worked, but it was fiddly, so I only ever bothered doing it on the two main pages.
But then i had a brainwave. If I wrap the “I” in a span, I can then target it with CSS, and manipulate it. Or, as it turns out, that doesn’t work. Much Googling later, I found a bunch of people explaining that you can’t use CSS to replace text, and lamenting that this would be so much easier if you could control the HTML. Botheration.
It wasn’t all bad news, as you can use CSS to add text after the original
content, using a rule scoped with the “:after” selector.
And I control the HTML. So, rather than trying to get CSS to remove the text, I
just don’t put it in. So I added an empty span element with a distinct class. I
then add a rule to add the replacement character in, tagged with “:after”. And
if i dont want a replacement character? Then i modify the CSS to replace the
character with “I”, which makes the logogram look normal.
This is so much easier, because I only need to make the change once, in the main CSS file, and the logogram changes on all of the pages. Win!
I suspect this only works with characters, but heck yeah unicode.
Roll on Hallowe’en!