First, you cannot directly style a character in CSS. You can style based on tag names, ids, classes, pseudo-elements, pseudo-classes and attributes.
So if you want to replace every "" with your own SVG in your code, you have several ways to achieve it:
If you're using PHP, use str_replace to look for every instance of your character and replace it with your SVG file as an <img>
element or an empty tag (e.g.: a <span>
) with your SVG as a background-image
.
// CSS
.my-emoji {
background-image: url(my-emoji.svg);
// don't forget "display", "height" and "width" attributes
}
// PHP
str_replace("", "<span class='my-emoji'></span>", $my_content);
// Then output $my_content where you want it.
If you're using Javascript, you can do the same with replace()
.
// CSS
//same as #1
// JS
var res = my_content.replace("", "<span class='my-emoji'></span>");
// Then output my_content where you want it.
If you have full control on your HTML, you can wrap every instance of "" with a tag and style it with CSS.
// HTML
<span class="my-emoji"></span>
// CSS
.my-emoji {
text-indent: -9999px;
background-image: url(my-emoji.svg);
// don't forget "display", "height" and "width" attributes
}
Careful not to forget url()
when using background-image
in CSS. In your example you gave background-image: new-emoji.svg
; it would have never worked, it's background-image: url(new-emoji.svg)
.