Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stacking Font-Awesome Star Icons (fa-star & fa-star-half)

I want to stack the two Font Awesome icons fa-star and fa-star-half, but I am having alignment issues. See image below:

Attempt to stack fa-star and fa-star-half fails due to alignment of icons

Here is my HTML:

<span class="fa-stack">
     <i class="fa fa-fw fa-lg fa-star-half fa-stack-1x"></i>
     <i class="fa fa-fw fa-lg fa-star fa-stack-1x"></i>
</span>

...and my CSS:

a-stack i.fa-star {
    color:transparent;
    -webkit-text-stroke-width: 1px;
    -webkit-text-stroke-color: orange;
}

.fa-stack i.fa-star-half {
    color:yellow;
    -webkit-text-stroke-width: 1px;
    -webkit-text-stroke-color: orange;
}

Note that I do not want to use fa-star-half-o which has an unappealing design when used with an outline.

I have tried to use "float," but without success. If I use "margin-left," the spacing is off. See image below:

enter image description here

Any help is appreciated. Thanks!

Jesse

like image 697
Jesse Avatar asked Jun 13 '15 21:06

Jesse


People also ask

How do I stack 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 difference between fa and FAS in Font Awesome?

Instead of fa as a style preceding every icon style, you need to pick from fas for solid, far for regular, fal for light, or fab for brand. It looks like fas is the fallback, so you get solid if you leave your old fa references. For most icons, this change makes the icon heavier or lighter.

What is fa FW in Font Awesome?

The fa-fw class is used to set icons at a fixed width. This class is useful when different icon widths throw off alignment.


2 Answers

Use the following margin-left to line up the image. Check it out here: https://jsfiddle.net/f63h157x/1/

enter image description here

.fa-stack i.fa-star-half {
    color:yellow;
    -webkit-text-stroke-width: 1px;
    -webkit-text-stroke-color: orange;
    margin-left: -5px;
}
like image 86
TheOnlyError Avatar answered Dec 07 '22 06:12

TheOnlyError


I think all you need to do is apply a text-align: left; to both of the <i /> elements and it should align properly without needing to use margin-left: 5px;

like image 39
Phillip Quinlan Avatar answered Dec 07 '22 04:12

Phillip Quinlan