Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS put html entity as content [duplicate]

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!

like image 925
Progo Avatar asked Apr 06 '14 15:04

Progo


People also ask

How use HTML entity in CSS content?

In CSS you need to use a Unicode escape sequence in place of HTML Entities. This is based on the hexadecimal value of a character. I found that the easiest way to convert symbol to their hexadecimal equivalent is, such as from ▾ ( &#9662; ) to \25BE is to use the Microsoft calculator =) Yes.

What is the use of HTML special characters?

Definition and Usage The htmlspecialchars() function converts some predefined characters to HTML entities.


1 Answers

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

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

like image 54
Quentin Avatar answered Sep 30 '22 12:09

Quentin