6

Using the css content property, I am trying to make put an HTML entity after an element.

Here is my HTML:

<table id="tic" cellpadding="0" cellspacing="0" border="5" bordercolor="black" bordercolorlight="gray" bgcolor="white">
    <tr>
        <td width="55" height="55" class="x"></td>
        <td width="55" height="55" class="o"></td>
        <td width="55" height="55" class="x"></td>
    </tr>
    <tr>
        <td width="55" height="55" class="o"></td>
        <td width="55" height="55" class="x"></td>
        <td width="55" height="55" class="o"></td>
    </tr>
    <tr>
        <td width="55" height="55" class="x"></td>
        <td width="55" height="55" class="o"></td>
        <td width="55" height="55" class="x"></td>
    </tr>
</table>

And my CSS:

table{
    text-align:center;
    font-size:2em;
    font-weight:bold;
}
td.o:after{
    content:"&#9675;";
    font-weight:bold;
}
td.x:after{
    content:"&#x2716;"
}

Unfortunately, instead of getting the ○ character and the ✖ character, I get the entity names.

FIDDLE

How can I fix this? Thanks!

Progo
  • 3,452
  • 5
  • 27
  • 44
  • http://unicode-table.com/ and use the answer from @dejakob for the code. Go nuts – Deryck Apr 06 '14 at 16:07
  • you have to use the escaped unicode.. check below stackoverflow.. http://stackoverflow.com/questions/190396/adding-html-entities-using-css-content – Deepak Sharma Apr 06 '14 at 16:09

4 Answers4

4

CSS isn't HTML. You can't use HTML entities in it.

Use the literal character () or a CSS unicode escape instead.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
3

You have to use the escaped unicode :

Like

td.o:after {
    content:"\00a2"; 
}
td.x:after {
    content:"\00a4"; 
}

More info on : http://www.evotech.net/blog/2007/04/named-html-entities-in-numeric-order/

Deepak Sharma
  • 4,124
  • 1
  • 14
  • 31
0

Try

td.o:after{
    content:"\9675";
    font-weight:bold;
}
td.x:after{
    content:"\2716"
}

For the first one, it gives another symbol, so please check if you used the right code for it...

http://jsfiddle.net/7XXbK/

dejakob
  • 2,062
  • 14
  • 21
0

Here's a working fiddle for you:

http://jsfiddle.net/Dp78c/4/

table{
    text-align:center;
    font-size:2em;
    font-weight:bold;
}
td.o:after{
    content:"\25CB";
    font-weight:bold;
} 
td.x:after{
    content:"\2716";
}

You need to use the unicode escaped character instead. You can use this tool to translate for you as well if you need to:

http://www.evotech.net/articles/testjsentities.html

slapthelownote
  • 4,249
  • 1
  • 23
  • 27