lichess.org
Donate

CSS tricks

I learned a very interesting technique today.

I needed a thought bubble icon and wanted to use a unicode character for this šŸ’­.

However to my surprise I could not color this using CSS, despite in general this works with unicode characters. It turns out that some unicode characters are implemented as a bitmap and coloring does not work on them.

There is an interesting hack, that can solve this issue:

stackoverflow.com/questions/32413731/color-for-unicode-emoji/39776303#39776303

šššš’ššŸ {
ā€€ā€€ššŒšš˜šš•šš˜šš›: šššš›ššŠšš—ššœšš™ššŠšš›ššŽšš—šš;
ā€€ā€€ššššŽšš”šš-ššœšš‘ššŠšššš˜šš : 0 0 0 šš›ššŽšš;
}

I have a DOM mapping, in which I wrap DOM elements in Javascript classes. You can set properties with member functions of this DOM wrapper class. Every setter functions returns the class, so you can chain this. I can say something like

š™³šš’ššŸ().šš‹ššŒ("#0šš0").šš (šŸ·00).šš‘(šŸ·00)

and this would create a green 100 x 100 div.

Now I can create a new property setter, which can do all the above trick:

ššššœšš‘(ššššŽšš”ššššœšš‘ššŠšššš˜šš ){
ā€€ā€€ā€€šššš‘šš’ššœ.ššŽ.ššœšššš¢šš•ššŽ.ššššŽšš”šššš‚šš‘ššŠšššš˜šš  = ššššŽšš”ššššœšš‘ššŠšššš˜šš 
ā€€ā€€ā€€šš›ššŽššššžšš›šš— šššš‘šš’ššœ
}

ššœšš‘ššŒ(ššœšš‘ššŠšššš˜šš ššŒšš˜šš•šš˜šš›){
ā€€ā€€ā€€šš›ššŽššššžšš›šš— šššš‘šš’ššœ.ššŒ("šššš›ššŠšš—ššœšš™ššŠšš›ššŽšš—šš").ššššœšš‘(`0 0 0 ${ššœšš‘ššŠšššš˜šš ššŒšš˜šš•šš˜šš›}`)
}

Note that I don't need "function" because this code is within a class definition.

From now on I can color unicode with one touch:

š™³šš’ššŸ().šš‘šššš–šš•("šŸ’­").ššœšš‘ššŒ("#00šš")

Looks like this:

https://imgur.com/yyIMEBP
Cool stuff! This is an unusual coincidence since I'm making a DOM -> html converter as a java project rn, and I hadn't even heard about it before the project (Yes, libraries already exist for this task, I know). Definitely looks better to make some of the emojis uniform colors and now you can make a reeeallly red angry face

This topic has been archived and can no longer be replied to.