Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly code UNICODE FONT ICONS so they render on all browsers

I want to add Unicode icons to a website, and only unicode -No custom font files.

I know I can do something like:

[class^=icon-facebook]:before {
    content: "\00066";
}
[class^=icon-twitter]:before {
    content: "\01F426";
}
[class^=icon-phone]:before {
    content: "\01F4DE";
}
[class^=icon-fax]:before {
    content: "\01F4E0";
}
[class^=icon-email]:before { 
    content: "\01F4E7";
}
[class^=icon-link]:before { 
    content: "\01F517";
}
[class^=icon-pay]:before {
    content: "\01F4B8";
}
[class^=icon-dollar]:before {
    content: "\01F4B5";
}
[class^=icon-yen]:before {
    content: "\01F4B4";
}
[class^=icon-save]:before {
    content: "\01F4B0";
}

jsFiddle

However, I am reading that some browsers won't render the "icon" (Unicode character) properly. Sometimes browsers would display an empty square instead of the Unicode character.

How can I code my CSS to prevent that from happening?

  1. No custom fonts
  2. No images
like image 479
Omar Avatar asked May 05 '15 20:05

Omar


People also ask

Do all browsers support Unicode?

No browser supports all of Unicode, or is required to do so. The specifications do not require that all characters, or any specific subset thereof, will be displayed properly.

How do I enable Unicode font?

Click on Start > Control Panel on the taskbar at the bottom left of your desktop. Select “Fonts” from the Control Panel. From the drop-down menus, choose File > Install New Font. Find the Unicode font you wish to instal in the folder or drive where the font file is located.

Why is Unicode not working?

If you are unable to read some Unicode characters in your browser, it may be because your system is not properly configured. Here are some basic instructions for doing that. There are two basic steps: Install fonts that cover the characters you need.

Are fonts Unicode?

The vast majority of modern computer fonts use Unicode mappings, even those fonts which only include glyphs for a single writing system, or even only support the basic Latin alphabet.


1 Answers

i understand that you dont want to make an "extra" call for a font download or image download. if you insist on keeping it all in the CSS you could try Base64 for example:

<style type="text/css">
div.image {
    width:            14px;
    height:           14px;
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNv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ZW5kPSJyIj8+AND5IAAAAHBJREFUeNpi/P//P4OJiQkDGmAG4r9AzATl/4Oy/zHgAWfOnIFrOAjE/5HwHyj9F4r/I9G48CEGJBdQA4AMZWCBcuypZSo1XUhbAw8SCHBi8EFkA/9TwXH/kCPFYeRFygEqRMoBmuQURlDhQE0AEGAA1LJE38CAHLYAAAAASUVORK5CYII=');
}
</style>

This will place the hamburger menu icon. Here is a working example: Demo

It will surely look exactly the same in all browser because it is an image and not a font.

you can make any png image into this here: PNG to Base64

Good luck :)

like image 194
Mike Avatar answered Oct 19 '22 00:10

Mike