Change color when hover a font awesome icon?

梦想与她 提交于 2019-11-27 02:32:14

问题


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.


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/25770590/change-color-when-hover-a-font-awesome-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!