Marco
Marco

Reputation: 389

Change Font Awesome icon on :hover

I hope this question was not already asked somewhere in this forum. I swear I searched it!

My goal is to change the "tag" icon when mouse is over it. Namely, I would like to let the "tags" icon appear replacing the old one.

I am quite sure there is an easy solution out there; probably using

.fa-tag:hover {
 background: url(something);
}

Here the page of my website with the .fa-tag icons : http://wordsinthebucket.com/about

Thank you in advance for your attention.

Upvotes: 19

Views: 44992

Answers (4)

dfsq
dfsq

Reputation: 193261

I would have two icons but have only one visible at a time, toggling them based on :hover state. I feel this is more flexible then messing with background.

.change-icon > .fa + .fa,
.change-icon:hover > .fa {
  display: none;
}
.change-icon:hover > .fa + .fa {
  display: inherit;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" rel="stylesheet" />

<span class="change-icon">
  Tags
  <i class="fa fa-tags"></i>
  <i class="fa fa-gear"></i>
</span>

Upvotes: 43

constanton
constanton

Reputation: 11

It's not a good idea to overwrite fa-tag as you might need it somewhere else in a different scope. I would go like this: http://antonakoglou.com/change-font-awesome-icon-content-hover/

which is actually the second part of this answer that I just discovered: https://stackoverflow.com/a/19503006

Upvotes: 1

Vitorino fernandes
Vitorino fernandes

Reputation: 15951

.fa-camera-retro:hover:before{
    content: "\f02d";
}

demo - http://www.bootply.com/oj2Io7btD7

you will need to change the content of :before pseudo element on hover

here is the list of complete fontawesome content codes

http://astronautweb.co/snippet/font-awesome/

Upvotes: 11

ckuijjer
ckuijjer

Reputation: 13814

You can by adding CSS like:

.fa-tag:hover:before {
  content: "\f02c"
}

which changes the content in the :before pseudo element when hovering over the .fa-tag.

I'm quite sure it's not a good idea to overwrite the .fa-tag styling. At least scope it by a parent class, e.g. .entry-content .fa-tag:hover:before (although I would prefer a better class name like author-tags.

Upvotes: 8

Related Questions