font awesome - stack circle color change on hover

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



font awesome - stack circle color change on hover



I am using the font awesome framework for the icons.




.fa-circle
color: red;


.fa-times
color: #fff;


.fa-circle:focus,
.fa-circle:hover
color: #fff;
border: 2px solid black;


.fa-times:focus,
.fa-times:hover
color: red;


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-times fa-stack-1x"></i>
</span>



enter image escription here



The above image is for the normal state.



On hover or focus, i want the circle color should change to white with red border and times icon shade changes to red. I need some kind of inverse on the hover action. But for some reason, it is not happening for the circle.



Please suggest where am i making the mistake.





using CSS alone would be great
– Karan
Aug 10 at 9:53




1 Answer
1



You can simplify the code like this, no need icon for the circle:




.fa-times
color: #fff;


.fa-stack
border-radius: 50%;
background: red;
box-sizing: border-box;
border: 1px solid transparent;
transition:.5s;


.fa-stack:hover
background: #fff;
border-color:#000;


.fa-stack:hover .fa-times
color: red;


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css">
<span class="fa-stack fa-lg">
<i class="fa fa-times fa-stack-1x"></i>
</span>



And considering your initial code the issue is that you are applying the hover on the child element but it should be applied to the parent because the circle won't be hover since it's under the cross:




.fa-circle
color: red;


.fa-times
color: #fff;


.fa-stack:hover .fa-circle
color: #fff;


.fa-stack:hover .fa-times
color: red;


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" >

<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-times fa-stack-1x"></i>
</span>





Thanks a ton :-)
– Karan
Aug 10 at 9:59





on hover, how can we make the border smooth.. Right now, it is looking little rough.
– Karan
Aug 10 at 10:03





@Karan simply add transition, check the edit of the first code
– Temani Afif
Aug 10 at 10:05





Just curious, we never used .fa-circle class in the html code. How come it is being used ?
– Karan
Aug 10 at 10:07





@Karan simply forget the CSS :) it's removed now, useless
– Temani Afif
Aug 10 at 10:08






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered