Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overlay a number on top of a FontAwesome glyph?

How can I overlay a number between 0 and 99 in the middle of 'icon-star-empty'?

like image 930
Nescio Avatar asked Jul 19 '13 02:07

Nescio


People also ask

Does Font Awesome have number icons?

We don't have any Free Solid icons in Numbers.

How do I overlay two font awesome icons?

To stack multiple icons, use the fa-stack class on the parent HTML element of the 2 icons you want to stack. Then add the fa-stack-1x class for the regularly sized icon and add the fa-stack-2x class for the larger icon. fa-inverse can be added to the icon with the fa-stack-1x to help with a knock-out looking effect.

What is the difference between glyph icons and font awesome?

Font Awesome is a font and icon toolkit based on CSS and Less. Glyphicons are icon fonts which you can use in your web projects.

What is fa-stack-2x?

fa-stack-2x. Used on the icon which should be displayed larger when stacked. fa-inverse. Inverts the color of the icon displayed at base size when stacked.


2 Answers

Simply do this from the Font Awesome docs on Stacked Icons:

<span class="fa-stack fa-lg">     <i class="fa fa-star-o fa-stack-2x"></i>     <i class="fa fa-stack-1x">1</i> </span> 

Font Awesome Docs Screenshot

like image 140
nilsi Avatar answered Nov 09 '22 03:11

nilsi


Here is what I use for counter overlays (badges) with FontAwesome (FA) 5.1. Unlike using the new fa-layers method, this does not require SVG+JS. Simply add a data-count attribute to <i> markup...

CSS

.fas[data-count]{     position:relative; } .fas[data-count]:after{     position: absolute;     right: -0.75em;     top: -.75em;     content: attr(data-count);     padding: .5em;     border-radius: 10em;     line-height: .9em;     color: white;     background: rgba(255,0,0,.75);     text-align: center;     min-width: 2em;     font: bold .4em sans-serif; } 

Markup

<i class="fas fa-envelope" data-count="8"></i> &nbsp; <i class="fas fa-address-book fa-lg" data-count="16"></i> &nbsp; <i class="fas fa-bookmark fa-2x" data-count="4"></i> &nbsp; <i class="fas fa-angry fa-3x" data-count="32"></i> &nbsp; <i class="fas fa-bell fa-4x" data-count="2"></i> 

Example

FontAwesome 5.x Badge Counter Overlays

Conclusion

Some FA icon sizes may require badge size/position tweaking, but works well for my purposes. All colors/positions can be adjusted for calendar overlays, text labels, or OP's star outline.

Note

Untested, but using the same CSS should work with older FA versions by changing fas class to fa instead.

like image 43
Mavelo Avatar answered Nov 09 '22 03:11

Mavelo