I am currently developing a unique social media platform using VueJS 3.
For the design aspect, I incorporated Twitter's iconic logo saved as an .svg file, easily displayed using the <img />
tag. To modify its color, I utilized the fill="#fff"
attribute within the <svg>
tag. However, I encountered a challenge when wanting to utilize the .svg file in multiple locations and various colors.
My attempt to dynamically change the svg's color by assigning classes like fill-white
, bg-white
, and text-white
to the <img />
tag proved to be ineffective.
The Current .svg File - Showing White Color
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24" aria-hidden="true">
<g>
<path fill="#fff" d="M23.643 4.937c-... 1.7-1.477 2.323-2.41z"></path>
</g>
</svg>
Img Tag Implementation
<img
src="/twitter-bird.svg"
draggable="false"
class="w-52 lg:w-96 fill-white"
alt="Twitter Bird"
/>
Attempt to Customize .svg File
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24" aria-hidden="true">
<g>
<path fill="params(fill) #fff" d="M23.643 4.937c-... 1.7-1.477 2.323-2.41z"></path>
</g>
</svg>
I am aware of the necessity to enable color modification for this svg file, but I am yet to discover the appropriate solution.