5

How do you implement an icon font?

Github uses them extensively on their webpage, yet trying to reproduce their implementation results in failure.

https://github.com/styleguide/css/7.0

See the attempted implementation here:

http://jsfiddle.net/spuder/jsmzm/7/

<div id="github">

    <span class="mega-icon mega-icon-blacktocat"></span>

</div>


.mega-icon-blacktocat {
    content:"\f209";
}



I've read many pages on icon fonts, and gone through several tutorials with no success

How to use icon fonts

http://css-tricks.com/examples/IconFont/

http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-ever-thought-about-using-font-face-for-icons/

Placing Unicode character in CSS content value

Beginner.

Update 2013-4-11 The solution provided works great in WebKit, it does not work in firefox 20.0 http://jsfiddle.net/jsmzm/10/

Community
  • 1
  • 1
spuder
  • 17,437
  • 19
  • 87
  • 153

3 Answers3

1

here is your fiddle updated
basically you were missing the data-icon attribute in your span tag

  <div id="github"> 
<span data-icon="" class="mega-icon mega-icon-blacktocat"></span>

and the reference in your css

[data-icon]:before {
  font-family:'Octicons Regular';
  content: attr(data-icon);
  speak: none; 
Yenn
  • 919
  • 6
  • 20
  • Excellent! I noticed you use the actual UTF character  . Is there a way to use the ascii value instead? I'm trying data-icon="\f209" with no luck. – spuder Apr 15 '13 at 00:38
1

Here is a very good article on How to Use Icon Fonts in Your Website

Mohit
  • 281
  • 4
  • 14
0

Most browsers don't support the content property to replace an element's contents. Its really only meant to be used on pseudo elements.

http://jsfiddle.net/jsmzm/11/

.mega-icon-blacktocat:before {
    content:"\f209";
}
cimmanon
  • 67,211
  • 17
  • 165
  • 171