I have added font icons to a list like this:
a:before {
font-family: FontAwesome;
content: "\f015";
.. etc..
}
When the parent anchor tag is hovered, I want this :before pseudo to be rotated. I tried this, but it is not working:
a:hover:before {
-webkit-transform:rotate(360deg);
-moz-transform:rotate(360deg);
-o-transform:rotate(360deg);
}
Doesnt this work? What can I do to get the rotate effect on the :before element only when the parent is hovered?
To clarify, you CAN NOT give :hover to a pseudo element. There's no such thing as ::after:hover in CSS as of 2018.
The :before and :after selectors in CSS is used to add content before and after an element. The :hover is pseudo-class and :before & :after are pseudo-elements. In CSS, pseudo-elements are written after pseudo-class.
Try this out:
a:before {
-webkit-transition: all 300ms 0s ease-in-out;
transition: all 300ms 0s ease-in-out;
content: "\f015";
display: inline-block; //as @Rohit Azad suggested
font-family: FontAwesome;
// .. etc ..
}
a:hover:before {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
Have a look at this fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With