I want the color of my SVG icon to be white by default and to become red on hover.
But in my current code it is always white and does not change on hover. Why?
Here is my code:
index.html file:
<img src="images/social/icon-facebook.svg" alt="facebook logo"
class="w-7 h-7 hover:fill-red-400">
icon-facebook.svg file:
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path fill="#FFF" d="M18.896 0H1.104C.494 0 0 .494 0 1.104v17.793C0 19.506.494 20 1.104 20h9.58v-7.745H8.076V9.237h2.606V7.01c0-2.583 1.578-3.99 3.883-3.99 1.104 0 2.052.082 2.329.119v2.7h-1.598c-1.254 0-1.496.597-1.496 1.47v1.928h2.989l-.39 3.018h-2.6V20h5.098c.608 0 1.102-.494 1.102-1.104V1.104C20 .494 19.506 0 18.896 0z"/>
</svg>
I also noticed, that defining the white default color with a Tailwind CSS class on the img
tag instead of using the fill
attribute in the SVG file doesn't work either - the icon will just be black.
Why do my Tailwind CSS classes not have any effect at all here?
index.html file:
<img src="images/social/icon-facebook.svg" alt="facebook logo"
class="w-7 h-7 fill-white hover:fill-red-400">
icon-facebook.svg file:
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20">
<path d="M18.896 0H1.104C.494 0 0 .494 0 1.104v17.793C0 19.506.494 20 1.104 20h9.58v-7.745H8.076V9.237h2.606V7.01c0-2.583 1.578-3.99 3.883-3.99 1.104 0 2.052.082 2.329.119v2.7h-1.598c-1.254 0-1.496.597-1.496 1.47v1.928h2.989l-.39 3.018h-2.6V20h5.098c.608 0 1.102-.494 1.102-1.104V1.104C20 .494 19.506 0 18.896 0z"/>
</svg>