Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of Font Awesome stacked icons on hover

I'm using two Font Awesome icons:

  • fa-circle-thin
  • fa-user-plus

They are stacked on top of one another to give a circle icon look.

<span class="fa-stack fa-sm">
 <i class="fa fa-circle-thin fa-stack-2x"></i>
 <i class="fa fa-user-plus fa-stack-1x "></i>
</span>

When I hover over I want the circle to be filled in black and the fa-user-plus to change to white. How can I achieve this?

See JSFiddle: http://jsfiddle.net/ReturnOfTheMac/Lwdaen75/

like image 514
Cathal Mac Donnacha Avatar asked Jun 16 '15 14:06

Cathal Mac Donnacha


People also ask

How do I recolor font awesome icons?

To change the color of the icons, simply add or change the “color” property in the CSS. So to change the color of the icons to red in the above example, add “color:red” to the .

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.

Can you edit font awesome icons?

Font Awesome icons can be customized even further using your own CSS. We've even added CSS Custom Properties to our style toolkit options.

How do I change my font awesome icon Weight?

Change fa-weight icon size To increase fa-weight font awesome icon size, use the fa-lg (33% increase), fa-2x, fa-3x, fa-4x, or fa-5x classes along with icon class fa-weight. Increase in icon size will be relative to their parent container.


1 Answers

To achieve the desired effect, add a fa-circle icon to the stack that will be transparent on display (opacity:0.0) and solid (opacity:1.0) on :hover.

For example (also on JSFiddle: http://jsfiddle.net/2hxxuv52/5/):

HTML

<span class="fa-stack fa-sm">
  <i class="fa fa-circle fa-stack-2x "></i>
  <i class="fa fa-circle-thin fa-stack-2x"></i>
  <i class="fa fa-user-plus fa-stack-1x "></i>
</span>

CSS

.fa-stack        .fa { color: black; }
.fa-stack        .fa.fa-circle-thin { color: black; }
.fa-stack        .fa.fa-circle { opacity:0.0; color:black; }

.fa-stack:hover  .fa.fa-user-plus { color: white; }
.fa-stack:hover  .fa.fa-circle-thin { color: black; }
.fa-stack:hover  .fa.fa-circle { opacity:1.0 }
like image 170
Grokify Avatar answered Nov 15 '22 07:11

Grokify