I’m trying to reproduce this heart-shaped "like" button:
Inactive state at the top, hovering at the bottom
The hover has to be animated with a transition, like this.
I’ve tried using FontAwesome and Material Icons, but I can’t figure out how to do a proper transition with them. background-color
leaves the borders of the icon.
2
Answers
I figure 2 ways of doing it, the first one:
In this way, you have to "draw" the heart manually with SVG, and then work on hover with css.
The second one:
That’s the one i prefer, but you have to work with a PNG who have the transparency inside the heart, or you’ll get (as the example) the entire image container coloured.
Hope it helps!
For icons like these, using Scalable Vector Graphics (SVGs) is ideal for a multitude of reasons, but in this specific case especially so because of the fact you can use CSS to style individual elements of the SVG.
The only downside to this is that you need to actually include the
svg
tag everywhere, including all it’s data. The styles can be in an external stylesheet though. Including the SVG as animg
or anobject
would prevent you from interacting with it’s styles.You also need to have two separate elements (the outline/border, and the filled in shape) inside the SVG, as CSS
border
oroutline
do not get applied to those elements, but their bounding box instead. There is of course thestroke
attribute that would work fine on the filled shape element, but you have no control over the direction of it (like applying the stroke inside the path), so it’s not ideal.The other solution would be using normal rasterized images stacked on top of one another and styling their opacity:
I’d definitely recommend using the SVG approach though, as it is just so much more flexible, and also has the advantage of being a vector image. Adding a gradient (like in your example) to the SVG would be as simple as adding a CSS
linear-gradient
to thebackground
of the.heart-fill
class. And you could of course animate that too.