Goal
I would like to create a web page for templating cards and other objects used in table top board games. Many games include a sort of "symbol font", i.e. a set of symbols with meaning in the context of the game, which are used inline with text. Therefore, my end goal is to be able to position several text fields over a background image and include multi-colored custom symbols with that text.
I imagine that what I am attempting requires techniques somewhat similar to whatever is done to support emojis.
I have succeeded in rendering custom symbols in the inner HTML of a <span>
.
However, I would like to render the symbols inline with text that can be positioned over an image.
How can this be done?
What I've tried
I drew a custom symbol in Inkscape, saved as a 32x32
svg
file. It is a half-yellow half-blue circle.I uploaded the symbol to icomoon and downloaded a font package. Icomoon produces
.tff
,.svg
, and.woff
font files. It also produces some example html and css.I pared down the html and css to a pretty minimal (not)working example:
demo.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Symbol font demo</title> <link rel="stylesheet" href="style.css"> </head> <body> <p>This code</p> <xmp> <div> <span class="my-fontcircle"><span class="path1"></span><span class="path2"></span></span> </div> </xmp> <p>Produces this</p> <div> <span class="my-fontcircle"><span class="path1"></span><span class="path2"></span></span> </div> <p>This code</p> <xmp> <div font-family: "my-font">Let's use our symbol in line: </div> </xmp> <p>Produces this</p> <div font-family: "my-font">Let's use our symbol in line: </div> </body> </html>
style.css
@font-face { font-family: 'my-font'; src: url('fonts/my-font.ttf?81gy7') format('truetype'), url('fonts/my-font.woff?81gy7') format('woff'), url('fonts/my-font.svg?81gy7#my-font') format('svg'); font-weight: normal; font-style: normal; font-display: block; } [class^="my-font"], [class*=" my-font"] { /* use !important to prevent issues with browser extensions that change fonts */ font-family: 'my-font' !important; speak: never; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; /* Better Font Rendering =========== */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .my-fontcircle .path1:before { content: "\e900"; color: rgb(251, 236, 0); } .my-fontcircle .path2:before { content: "\e901"; margin-left: -1em; color: rgb(0, 129, 255); }
The result looks like this:
As we can see, the symbol shows up when we use the css class method, but it doesn't render in text. How can we make the symbol show up inline with text?