I'm trying to align 4 icons in a row for the share functionality of a website. When I was using 4 normal icons they aligned perfectly and were the same size. Now I'm trying to have one of them stacked so that it has a border and it's creating some problems
Below is code I've been playing with:
<div class="share-results">
<a class="fa fa-2x fa-envelope-o" data-toggle="tooltip" title="Share by Email" data-placement="top" href="#"></a>
<a class="fa fa-2x fa-facebook-square" data-toggle="tooltip" title="Share on Facebook" data-placement="top" href=""></a>
<a class="fa fa-2x fa-twitter-square" data-toggle="tooltip" title="Share on Twitter" data-placement="top" href=""></a>
<a class="fa fa-2x fa-stack" data-toggle="tooltip" title="Share by Link" data-placement="top" href="#">
<i class="fa fa-square-o fa-stack-2x"></i>
<i class="fa fa-link fa-stack-1x"></i>
</a>
</div>
This creates:
It seems like there's just a sizing problem, so I played around with using fa-lg:
And also without any sizing helper on the stacked element:
Does anyone know how to align an icon with fa-2x to a stacked icons?
There is a way to accomplish this task with minimum usage of new CSS styles:
We should use envelope which has the same style as twitter and facebook, I mean square-style with fa-envelope-square class. And make all anchor items stacked:
<div class="share-results">
<a class="fa-stack fa-1x" data-toggle="tooltip" title="Share by Email" data-placement="top" href="#">
<i class="fa fa-envelope-square fa-stack-2x"></i>
</a>
<a class="fa-stack fa-1x" data-toggle="tooltip" title="Share on Facebook" data-placement="top" href="">
<i class="fa fa-facebook-square fa-stack-2x"></i>
</a>
<a class="fa-stack fa-1x" data-toggle="tooltip" title="Share on Twitter" data-placement="top" href="">
<i class="fa fa-twitter-square fa-stack-2x"></i>
</a>
<a class="fa-stack fa-1x" data-toggle="tooltip" title="Share by Link" data-placement="top" href="#">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-inverse fa-link fa-stack-1x"></i>
</a>
</div>
In addition to this we change margin between stacked elements to make them look as in your example:
.fa-stack { margin: -2px; }
The result would look like this:
Demo fiddle
I couldn't figure out a durable solution using the fa-* classes alone, but I did come up with a couple of ways to accomplish this that are admittedly slightly hacky, but not terribly hacky.
The first approach superimposes the fa-link icon, as text, over a normal fa fa-2x fa-square-o icon.
<div class="share-results">
<a class="fa fa-2x fa-envelope-o" data-toggle="tooltip" title="Share by Email" data-placement="top"></a>
<a class="fa fa-2x fa-facebook-square" data-toggle="tooltip" title="Share on Facebook" data-placement="top"></a>
<a class="fa fa-2x fa-twitter-square" data-toggle="tooltip" title="Share on Twitter" data-placement="top"></a>
<a class="fa fa-2x fa-square-o stacked" data-toggle="tooltip" title="Share by Link" data-placement="top"></a>
</div>
<style>
.stacked {
position:relative;
}
.stacked:after {
position: absolute;
font-family: FontAwesome;
font-size: .6em;
top:6px;
left:4px;
content: "\f0c1"; /*link icon*/
}
</style>
The second approach uses a combination of position: fixed and a custom font-size to help the new link align slightly better:
<div class="share-results">
<a class="fa fa-2x fa-envelope-o" data-toggle="tooltip" title="Share by Email" data-placement="top"></a>
<a class="fa fa-2x fa-facebook-square" data-toggle="tooltip" title="Share on Facebook" data-placement="top"></a>
<a class="fa fa-2x fa-twitter-square" data-toggle="tooltip" title="Share on Twitter" data-placement="top"></a>
<a class="fa fa-2x fa-stack stacked2" data-toggle="tooltip" title="Share by Link" data-placement="top">
<i class="fa fa-square-o fa-stack-2x"></i>
<i class="fa fa-link fa-stack-1x"></i>
</a>
</div>
<style>
.stacked2 {
position: fixed;
font-size: 1.1em !important;
top: -7px;
left: -4px;
}
</style>
The second approach is a little more accurate, but I've included the first for completeness if you'd like to play around with it. Here are the end results, respectively:
And here's a CodePen example.
I'm not sure if this answers your question, but I hope this helps a little.
Since the font awesome icons are all about widths, heights and line heights I tried to create a solution where all their values were the same to (hopefully) avoid confusion and to make it easier to update moving forward.
Using the example you gave I set these CSS properties:
.fa {
/*this sets values for all icons*/
color: gray;
font-size: 50px;
line-height: 55px;
text-decoration: none;
}
.fa-link {
/*make inner icon smaller but keep line-height the same so its centered vertically*/
font-size: 30px;
}
.fa-stack-cust {
position: relative;
display: inline-block;
width: 50px;
height: 50px;
line-height: 55px;
}
I wrapped the icons within a un-ordered list and the are now showing all on the same line. Here is the JS.Fiddle showing you a working example. You will be able to see the HTML changes even though they are minor. Hope that helps.
Related
I've tried a few variations of CSS star ratings via different methods, and am trying to implement the following via FontAwesome rather than using a sprite. I want to be able to include half stars ideally, but this is where the example below is failing. This is what I've tried so far. I can't get the half / partial star to work correctly here. Any pointers greatly appreciated!
.score {
display: block;
font-size: 16px;
position: relative;
overflow: hidden;
}
.score-wrap {
display: inline-block;
position: relative;
overflow: hidden;
height: 19px;
}
.score .stars-active {
color: #EEBD01;
position: relative;
z-index: 10;
display: inline-block;
}
.score .stars-inactive {
color: grey;
position: absolute;
top: 0;
left: 0;
-webkit-text-stroke: initial;
overflow: hidden;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:88%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:50%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:100%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:0%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
The overflow:hidden needs to be on 'stars-active' (the sized element) instead of 'score-wrap' (which never overflows.) You can use white-space: nowrap to prevent the stars from wrapping to the next line within the hidden-overflow container.
.score {
display: block;
font-size: 16px;
position: relative;
overflow: hidden;
}
.score-wrap {
display: inline-block;
position: relative;
height: 19px;
}
.score .stars-active {
color: #EEBD01;
position: relative;
z-index: 10;
display: inline-block;
overflow: hidden;
white-space: nowrap;
}
.score .stars-inactive {
color: grey;
position: absolute;
top: 0;
left: 0;
-webkit-text-stroke: initial;
/* overflow: hidden; */
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:88%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:50%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:100%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:0%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</span>
<span class="stars-inactive">
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</div>
</span>
I found this solution by Paales here: https://github.com/FortAwesome/Font-Awesome/issues/717
I think it's an elegant solution. It looks comparable to your code because the full stars overlap the empty stars and by using overflow: hidden and position: absolute. Now you can set the width of the full stars and show partly filled stars. If you want to show half stars you could change the width of the absolute positioned element with 10% increments.
.rating-box {
position:relative;
vertical-align: middle;
font-size: 3em;
font-family: FontAwesome;
display:inline-block;
color: #F68127;
}
.rating-box:before{
content: "\f006 \f006 \f006 \f006 \f006";
}
.rating-box .rating {
position: absolute;
left:0;
top:0;
white-space:nowrap;
overflow:hidden;
color: #F68127;
}
.rating-box .rating:before {
content: "\f005 \f005 \f005 \f005 \f005";
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="rating-box">
<div class="rating" style="width:30%;"></div>
</div>
PS: Daniel Beck already gave you the answer about the mistake you made regarding white-space: no-wrap, so I suggest accepting that answer. I just wanted to share this solution because I think it is a very nice alternate approach.
below is the Font Awesome 5 version of #Rob's answer above:
We can use font-family: "Font Awesome 5 Free"; font-weight: xxx; to switch between solid and outline
You can play around with the code at the following link.
/* rating box with fontawesome 5 inspired from - https://stackoverflow.com/a/49343426/6908282*/
.rating-box {
position: relative;
vertical-align: middle;
font-size: 3em; /* comment/edit this to change size */
font-family: FontAwesome;
display: inline-block;
color: #F68127;
}
.rating-box:before {
font-family: "Font Awesome 5 Free";
font-weight: 400;
content: "\f005 \f005 \f005 \f005 \f005";
}
.rating-box .rating {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
overflow: hidden;
color: #F68127;
}
.rating-box .rating:before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f005 \f005 \f005 \f005 \f005";
}
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
<div class="rating-box">
<div class="rating" style="width:52%;"></div>
</div>
I find myself doing with two sets of stars styles solid and regular. Solid set declared first to have higher z-index and overlapped Regular sets of stars controlled by hidden, nowrap and width.
.stars-rating {
position: relative;
display: inline-block;
}
.stars-rating .stars-score {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
width: 20%;
white-space: nowrap;
}
<div class="stars-rating">
<div class="stars-score" style="width: 20%">
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
</div>
<div class="stars-scale">
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
</div>
</div>
For future reference, FontAwesome have added half stars to their arsenal. Make sure to include <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> in the <head> section of your page, and then the following will give you the basic structure.
<span class="score">
<div class="score-wrap">
<span class="stars-active" style="width:88%">
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star-half" aria-hidden="true"></i>
</span>
</span>
</div>
If you want the stars to appear bigger, edit fa fa-star to be fa fa-star 3x where 3x indicates the size, so 3x, 4x, 5x etc. If you would like a different style of star, use fa-star-o. The default colour is black, so if you would like to change the colour you can either edit it via CSS or add the colour to the class, i.e class="fa-star-o bg-light"
This is very nice, thanks for sharing.
I made the same tweak as Faraz, switching to
<i class="fas fa-star" aria-hidden="true"></i>
in the stars-active span, and
<i class="far fa-star" aria-hidden="true"></i>
in stars-inactive,
as it bothered me that stars above the rating % didn't show.
★★★⯪☆
Just use Unicode characters and then use https://www.babelstone.co.uk/Fonts/Shapes.html font as it has ⯪ (STAR WITH LEFT HALF BLACK)
★★★⯪☆
Given the characters (glyphs) above, lets say that ⯪ is rendered as ▯ or some other character that denotes that the glyph is missing from the font. The way you fix this is that you copy ⯪ (missing glyph) and then
in google type
Unicode ⯪
(you paste the glyph you are looking for).
From the results you find https://unicode-table.com/en/2BEA/ that says that the character is called "Star with Left Half Black" and that the code is U+2BEA.
Next you take the 2BEA portion of U+2BEA and paste it into the URL below between /char/ and /fontsupport.htm
https://www.fileformat.info/info/unicode/char/2BEA/fontsupport.htm
The URL for your missing character lists all the fonts that contain that character. Now you can click "view" next to each font listed and find the one you like best.
If you find multiple that you like equally well, you can download all of them and then pick the smallest one.
You want to have a .ttf, .woff, and .woff2 version of the font you choose and then you can use it in CSS as follows:
#font-face {
font-family: 'BabelStoneShapes';
src: url('/fonts/BabelStoneShapes.woff2')format('woff2'), /* Smallest file, if your browser can use this, it will stop here and not download the rest */
url('/fonts/BabelStoneShapes.woff')format('woff'), /* A larger file, if your browser does not understand woff2 */
url('/fonts/BabelStoneShapes.ttf')format('truetype');/* The largest of the three */
font-weight: normal;
font-style: normal;
font-display: block;
}
div.rating {
font-family: BabelStoneShapes;
}
and then use it in HTML as follows:
<div class="rating">★★★⯪☆</div>
Obviously, if Stack Overflow wanted to, they could make their website support virtually all Unicode fonts by using Symbola and updating it each time a new version came out. But they probably never will so in this "Answer" you won't see the half star, but if you follow the example, you will.
I am trying to implement similar to the one in the attachment.
Below is my code. i get the envelope icon but dont know how to get the expected result by placing another icon.
<i class="fa fa-envelope-o" aria-hidden="true"></i>
Thanks
.wrap{
display: inline-block;
position: relative;
}
.wrap > .fa-commenting-o{
position: absolute;
top: -3px;
left: 10px;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'/>
<div class="wrap">
<i class="fa fa-envelope-o" aria-hidden="true"></i>
<i class="fa fa-commenting-o" aria-hidden="true"></i>
</div>
Do you want like this?
Try this:
.text-danger {
color: #d9534f;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'/>
<div class="container">
<span class="fa-stack fa-lg" aria-hidden="true">
<i class="fa fa-camera fa-stack-1x"></i>
<i class="fa fa-ban fa-stack-2x text-danger"></i>
</span>
</div>
Place your <i></i>s in a span like: Check Fontawesome examples
<span class="fa-stack fa-lg">
<i class="fa fa-envelope-o fa-stack-2x"></i><!--Make background icon large-->
<i class="fa fa-commenting-o fa-stack-1x"></i><!--make foreground icon smaller-->
</span>
Let me know how it works for you.
Have fun
You can overlap icons using CSS property. Try this
<span class="fa-stack fa-lg">
<i class="fa fa-envelope-o fa-stack-2x"></i>
<i class="fa fa-commenting fa-stack-2x" style="padding-left:22px;margin-top:-16px;z-index:232"></i>
</span>
check it on fiddle here
I have created FAB button on page that has scroll bar. My expectation is FAB button will be sticky on right down corner when page is getting scrolled. However, the button also scroll with page. This gives indication that z-index of FAB is at same level as other HTML tags but in CSS, I have specifically given z-index of FAB as 1000 (so I expect it to be higher than other element on page)
I have created fiddle to replicate issue. Can anyone please check and provide corrective action
https://jsfiddle.net/jh7mv590/2/
<div class="container">
<div class="row">
<div id="inbox">
<div class="fab btn-group show-on-hover dropup">
<div data-toggle="tooltip" data-placement="left" title="Compose" style="margin-left: 42px;">
<button type="button" class="btn btn-danger btn-io dropdown-toggle" data-toggle="dropdown">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x fab-backdrop"></i>
<i class="fa fa-plus fa-stack-1x fa-inverse fab-primary"></i>
<i class="fa fa-pencil fa-stack-1x fa-inverse fab-secondary"></i>
</span>
</button></div>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li><i class="fa fa-coffee"></i></li>
<li><i class="fa fa-comments-o"></i></li>
<li><i class="fa fa-hand-o-up"></i></li>
<li><i class="fa fa-ticket"></i></li>
</ul>
</div>
</div>
</div>
A bit late, but position: fixed; is probably what you are looking for.
.show-on-hover {
position: fixed;
bottom: 50px;
right: 50px;
}
I am trying to align vertical blocks containing icons and some text. Everything works as expected until the text is too large for the block.
.big-icons .big-icon {
font-size: 42px;
margin-bottom: 10px;
text-align: center;
line-height: 3.2em;
}
.big-icons .big-icon a .text {
font-size: 18px;
position: relative;
text-transform: uppercase;
top: 3em;
white-space: nowrap;
}
.big-icons .big-icon a {
font-weight: 300;
text-decoration: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="big-icons">
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-magic fa-stack-1x fa-inverse"></i>
<span class="text">Short title</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-area-chart fa-stack-1x fa-inverse"></i>
<span class="text">Very long long text</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
<span class="big-icon">
<a target="_blank" href="#">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-dropbox fa-stack-1x fa-inverse"></i>
<span class="text">Title</span>
</span>
</a>
</span>
<div class="visible-xs divider"></div>
</div>
How do i make the link containing text "Very long long text" to not intersect with text "Title" on the right ?
Seems like the fa-stack-1x class gives the icon position:absolute and thats why its not being centered properly. I would try to use fa just to render the icon in certain size and do everything else in my own css. The circle with border radius, own position etc.
How can I overlay a number between 0 and 99 in the middle of 'icon-star-empty'?
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>
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>
<i class="fas fa-address-book fa-lg" data-count="16"></i>
<i class="fas fa-bookmark fa-2x" data-count="4"></i>
<i class="fas fa-angry fa-3x" data-count="32"></i>
<i class="fas fa-bell fa-4x" data-count="2"></i>
Example
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.
This can also be done using Font Awesome Layers using version 5.0
<div class="fa-4x">
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-circle" style="color:Tomato"></i>
<i class="fa-inverse fas fa-times" data-fa-transform="shrink-6"></i>
</span>
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-bookmark"></i>
<i class="fa-inverse fas fa-heart" data-fa-transform="shrink-10 up-2" style="color:Tomato"></i>
</span>
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-play" data-fa-transform="rotate--90 grow-2"></i>
<i class="fas fa-sun fa-inverse" data-fa-transform="shrink-10 up-2"></i>
<i class="fas fa-moon fa-inverse" data-fa-transform="shrink-11 down-4.2 left-4"></i>
<i class="fas fa-star fa-inverse" data-fa-transform="shrink-11 down-4.2 right-4"></i>
</span>
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-calendar"></i>
<span class="fa-layers-text fa-inverse" data-fa-transform="shrink-8 down-3" style="font-weight:900">27</span>
</span>
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-certificate"></i>
<span class="fa-layers-text fa-inverse" data-fa-transform="shrink-11.5 rotate--30" style="font-weight:900">NEW</span>
</span>
<span class="fa-layers fa-fw" style="background:MistyRose">
<i class="fas fa-envelope"></i>
<span class="fa-layers-counter" style="background:Tomato">1,419</span>
</span>
</div>
You css should look something like:
.contain-i-e-s,.icon-empty-star,.text-i-e-s{
height:100px; width:100px;
}
.contain-i-e-s{
position:relative;
}
.text-i-e-s{
text-align:center; position:absolute;
}
Your HTML might look like:
<div class='contain-i-e-s'>
<i class='icon-empty-star'></i>
<div class='text-i-e-s'>99</div>
</div>