Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fallback for using unicode with css

Tags:

css

unicode

I was wondering if you could create a fallback when using unicode characters. See I got following css:

.icon-check:after {
    content:'\2714';
    color: green;
}

and one would have no support for this character, is there a way to just print 'yes' or something?

For fonts there it's easy , just like p{font-family:"Times New Roman", Times, serif;}. But for the content attribute, there seems no way to create such a fallback.

N.B. I know there other possibilities like Font Awesome, Glyphicons and similar but I am just interested if there is a fallback.

like image 940
Jacob van Lingen Avatar asked Mar 13 '14 14:03

Jacob van Lingen


People also ask

What is fallback in CSS?

The fallback descriptor can be used to specify a counter style to fall back to if the current counter style cannot create a marker representation for a particular counter value.

What is Unicode range in CSS?

The unicode-range CSS descriptor sets the specific range of characters to be used from a font defined by @font-face and made available for use on the current page. If the page doesn't use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.

What is fallback font for editing?

A fallback font is a reserve typeface containing symbols for as many Unicode characters as possible. When a display system encounters a character that is not part of the repertoire of any of the other available fonts, a symbol from a fallback font is used instead.


1 Answers

is there a way to just print 'yes' or something?

Simple answer? No.

I was wondering if you could create a fallback when using unicode characters

Simple answer? Yes...ish.

The only fallback you can specify is on the font family, however you can use @fontface to specify the unicode range of the font you're using.

The unicode-range CSS descriptor sets the specific range of characters to be downloaded from a font defined by @font-face and made available for use on the current page.

There is a great article on 24 Ways which outlines how this can be done, you could for example, specify a font-family just for the character in question e.g.(from the article):

@font-face {
    font-family: 'Ampersand';
    src: local('Baskerville'), local('Palatino'), local('Book Antiqua');
    unicode-range: U+26;
}

Then do:

.icon-check:after {
    content:'\26';
    color: green;
}

Nb. the above is for an ampersand but should give you an idea of one approach .

like image 119
SW4 Avatar answered Sep 30 '22 10:09

SW4