It's possible to include Emoji characters in modern browsers, but how can one make it a single color and choose that color?
For example, here is some Emoji and some regular (plane 0) Unicode symbols. All should be red, but only the symbols are rendered in red.
Associated HTML + CSS:
<p>
I wanted to do this myself so I've recently come up with a solution using newer CSS effects that works on Firefox and Edge as well.
Using filter, you first normalize the color by using sepia(1), you then saturate the heck out of it to get a pure red. If you want to get rid of black lines, suck the contrast out of the emoji before applying other filters using contrast(0). After that you just spin the colour wheel from red to whatever color you'd like using hue-rotate(). Note that because I used decimal values instead of %'s, a value of 100 means 10000%.
Hue offsets are defined as beginning at red. We are lucky that sepia is mostly red so the wheel starts off perfectly at 0-degrees. You can calculate what offset you want using a RGB to HSL converter. I found a nice one written in Javascript here: https://web.archive.org/web/20180808220922/http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
You must multiply the hue value by 360 to get the desired result from that function. An example would be
rgbToHsl(0,100,100)[0]*360
. Which would return 180. Since there is no red, this would be the expected result, you would be spinning 180 degrees away from red.As Litherium an Crissov pointed out, there are text emojis as well. These work better with transformations and often look better. You can't apply the method I have described above however, until you first apply
invert(.5)
on the text emojis, this is because the functions need some sort of shade to operate on. So simply addinginvert(.5)
to the beginning of each formula, allows for them to operate on both code points on all browsers.Some, but not all, code points can be drawn in either text form (non-picture-based glyph) or emoji form (picture-based glyph). Unicode describes that these two forms can be selected by using one of two variation selectors: either U+FE0E (VARIATION SELECTOR-15) or U+FE0F (VARIATION SELECTOR-16). When drawn in non-picture-based form, the
color
CSS property should apply.Example:
U+2603 (SNOWMAN) is drawn this way: ☃
The sequence of code points U+2603 U+FE0E is drawn this way: ☃︎
The sequence of code points U+2603 U+FE0F is drawn this way: ☃️
More information, along with a full list of the code points which participate in these variation sequences, can be found at http://unicode.org/emoji/charts/emoji-variants.html
(Note that different operating systems may choose a different default when the bare code point is used. For example, try viewing this post in macOS and iOS - the bare code point above looks different!)
Yes, you can color them!
You can fill them with a solid color:
Not every emoji works the same. Some are old textual symbols that now have an (optional or default) colorful representation, others were explicitly (only) as emojis. That means, some Unicode codepoints should have two possible representations,
text
andemoji
. Authors and users should be able to express their preference for one or the other. This is currently done with otherwise invisible variation selectors U+FE0E (text
, VS-15) and U+FE0F (emoji
, VS-16), but higher-level solutions (e.g. for CSS) have been proposed.The text-style emojis are monochromatic and should be displayed in the foreground color, i.e.
currentcolor
in CSS, just like any other glyph. The Unicode Consortium provides an overview of emojis by style (beta version). You should be able to append︎
in HTML to select the textual variant with anything in the columns labeled “Default Text Style; has VSs” and “Default Emoji Style; has VSs”. This doesn’t include the example emojisAs Emoji is quite new, styling it is not yet supported natively.
The workaround is to use an Emoji font such as Twitter's Twemoji. Then it can be styled much the same way Font Awesome or native Unicode can be styled.
采纳回答
编辑标签
举报内容
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
付费偷看金额在0.1-10元之间