How to change attributes in a svg icon in Tailwind css 4 #17393
-
Hello I would like to know if someone can help me out. I recently tried coding with tailwind css and so far i understood everything, the problem i'm having is how do i style svg icons. Neiter the fill or stroke actions do something but when i write text-slate-900 it changes the color of the icon. That said, that is the only thing that i can change, i cant make hover effects or scale effects beacuse it doesnt do anything. Do any of you guys have an idea why ?. I would like to make a hover affect that changes the stroke color of the icon and also that it scales wen you hover over it. The icon is from heroicon. Thanks for the help. here is the code
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Try something like this. The <div class="flex space-x-10 p-8">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="stroke-2 size-10 bg-amber-500 text-blue-400 hover:scale-125 transition duration-150 ease-in-out">
<path stroke-linecap="round" stroke-linejoin="round" d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 0 0 2.25-
2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-
1.21.38a12.035 12.035 0 0 1-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963
3.102a1.125 1.125 0 0 0-1.091-.852H4.5A2.25 2.25 0 0 0 2.25 4.5v2.25Z" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
class="stroke-1 size-10 bg-purple-500 hover:text-amber-300 hover:scale-225 transition duration-150 ease-in-out">
<path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-
2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5
4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
class="stroke-3 size-10 bg-sky-500 hover:stroke-emerald-700">
<path stroke-linecap="round" stroke-linejoin="round" d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.963 0a9 9 0 1 0-11.963 0m11.963 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
</div> |
Beta Was this translation helpful? Give feedback.
Try something like this. The
stroke="currentColor"
is why setting the text color changes the stroke. Here are a couple of examples of changing the color, stroke and scale with tailwind. There is a link below to the same code on Tailwind Play so you can mess around with it.