Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change between two fontawesome icons on hover?

I have an anchor tag with a font-awesome icon as follows

<a href="#" class="lock"><i class="icon-unlock"></i></a> 

Is it possible to change to icon on hover to a different icon?

my CSS

.lock:hover{color:red} 

Aside from the icon turning red I'd also like to change the icon to the following

<i class="icon-lock"></i> 

Is this possible without the help of JavaScript? Or do I need Javascript/Jquery on hover for this?

Thank you.

like image 954
BaconJuice Avatar asked Oct 21 '13 19:10

BaconJuice


People also ask

How can I change image on hover?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.

How do I overlay two 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.


1 Answers

You could toggle which one's shown on hover:

HTML:
<a href="#" class="lock">     <i class="icon-unlock"></i>     <i class="icon-lock"></i> </a> 
CSS:
.lock:hover .icon-unlock, .lock .icon-lock {     display: none; } .lock:hover .icon-lock {     display: inline; } 

Or, you could change the content of the icon-unlock class:

.lock:hover .icon-unlock:before {     content: "\f023"; } 
like image 138
zzzzBov Avatar answered Sep 23 '22 00:09

zzzzBov