46

Base in the Font Awesome documentation I create this icon:

<span class="fa-stack fa-5x">
  <i class="fa fa-circle fa-stack-2x"></i>
  <i class="fa fa-flag fa-stack-1x fa-inverse"></i>
</span>

This code create this html:

<span class="fa-stack fa-5x">
  <i class="fa fa-circle fa-stack-2x">::before</i>
  <i class="fa fa-flag fa-stack-1x fa-inverse">::before</i>
</span>

It is a stacked Flag icon. I want to change the icon color on Hover event, I tried with all these:

.fa-stack:hover{
color: red
}
.fa-stack i:hover{
color: red
}
.fa-stack i before:hover{
color: red
}

but not working.

Juan
  • 4,910
  • 3
  • 37
  • 46
JPashs
  • 13,044
  • 10
  • 42
  • 65

2 Answers2

76

if you want to change only the colour of the flag on hover use this:

http://jsfiddle.net/uvamhedx/

.fa-flag:hover {
    color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<i class="fa fa-flag fa-3x"></i>
Juan
  • 4,910
  • 3
  • 37
  • 46
6

use - !important - to override default black

.fa-heart:hover{
   color:red !important;
}
.fa-heart-o:hover{
   color:red !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<i class="fa fa-heart fa-2x"></i>
<i class="fa fa-heart-o fa-2x"></i>
Jifri Valanchery
  • 189
  • 5
  • 15
  • 8
    Is `!important` is really necessary? Many consider it as anti-pattern in programming. – Maris B. May 10 '19 at 10:04
  • 3
    using Important is not a good solution since it cannot be overwritten. You can overwrite all non inline css using specificity – Houman Mar 10 '20 at 05:14
  • I had to use !important to get this to work, unfortunately, but the icon was also within an ag-Grid, if that means anything. For an Angular project, I also had to put it in the styles.css file - it would not work in the component.css – ewomack Oct 07 '20 at 13:38