5

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,304
  • 5
  • 24
  • 43
  • 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

3

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

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

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
2

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,079
  • 1
  • 13
  • 30
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
  • 1,912
  • 13
  • 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,209
  • 1
  • 22
  • 27