So, I have the following HTML structure:
<ul>
<li data-content="\ec00"></li>
<li data-content="\ec01"></li>
</ul>
When using the data-content attribute in CSS to read the content:
li:before { content: attr(data-content) }
It shows ec00 and ec01 instead of those with backslashes.
Any ideas how I could go about this?
The idea behind is for a colorpicker for a huge amounts of icons.
Thanks in advance, Dorian
That is because you are using a character encoding that is not parsed properly in HTML. Remember that the CSS accesses the
data-
attributes as plaintext, and since HTML is does not parse hexadecimal characters,\ec00
is not parsed as it is supposed to be compared to when it is used as-is in a CSS file.What you could do is:
data-
attribute
(becauseec00
in hexadecimal is60416
in decimals, and\ec00
is used to force parsing in CSS while&#...;
is used to indicate a decimal entity in HTML)An example would be the copyright symbol:
169
. In HTML, you will use©
00A9
. In CSS, you will use\00A9
while in JS you will use\u00A9
And here is a proof-of-concept demo: