SVG fill not updating

I am trying to make my last star color gray. I have selected and written the style but its simply not applying. How can I fix?
<div class="d-flex column-gap-2">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img class="gray-star" src="./assets/images/star.svg" alt="Star">
</div>
<div class="d-flex column-gap-2">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img src="./assets/images/star.svg" alt="Star">
<img class="gray-star" src="./assets/images/star.svg" alt="Star">
</div>
img[alt="Star"] {
transform: none;
}

.gray-star {
fill: gray !important;
}
img[alt="Star"] {
transform: none;
}

.gray-star {
fill: gray !important;
}
That start svg
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="15.239" viewBox="0 0 16 15.239">
<path id="f35e3bcbde3528bceb03a6a775c06def" d="M-54.987,56.259c-.569.405-4.222-2.165-4.921-2.17s-4.393,2.505-4.956,2.091.76-4.673.549-5.338-3.747-3.392-3.526-4.054,4.691-.723,5.261-1.129,2.077-4.6,2.777-4.6,2.139,4.226,2.7,4.64,5.031.548,5.242,1.213-3.369,3.335-3.591,4S-54.418,55.854-54.987,56.259Z" transform="translate(67.851 -41.064)" fill="#f8b84e"/>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="15.239" viewBox="0 0 16 15.239">
<path id="f35e3bcbde3528bceb03a6a775c06def" d="M-54.987,56.259c-.569.405-4.222-2.165-4.921-2.17s-4.393,2.505-4.956,2.091.76-4.673.549-5.338-3.747-3.392-3.526-4.054,4.691-.723,5.261-1.129,2.077-4.6,2.777-4.6,2.139,4.226,2.7,4.64,5.031.548,5.242,1.213-3.369,3.335-3.591,4S-54.418,55.854-54.987,56.259Z" transform="translate(67.851 -41.064)" fill="#f8b84e"/>
</svg>
Please help me
No description
18 Replies
13eck
13eck4d ago
First off, get rid of !important and never use it again. It's a cancer that will infest your CSS files until everything is !important as you're trying to override other "important" things. Pretend it doesn't exist and your life will be better off, trust me. For the star issue, give me a few minutes to play around and see what I can figure out I'm 90% sure that you need the SVG to be inlined and not linked to modify it via CSS. So you could either inline all the stars or make a second star with the right colour and link that one.
b1mind
b1mind4d ago
Correct it needs to be the SVG element to modify not a img
13eck
13eck4d ago
Thanks for the confirmation, good sir! Thought I was going crazy lol
b1mind
b1mind4d ago
Best trick is to use custom props with a currentColor fallback imo
Shayokh
ShayokhOP4d ago
Alright Done sir! Just to make sure, I ran Vite and Scss watch multiple times, deleted cache but still problem persists. The latter sounds great I wish I could do this project in JSX/TSX and Tailwind. But my client asked for raw html, css and Bootstrap...Can't express my disgust in words
13eck
13eck4d ago
Raw CSS or Bootstrap? Can't do both :p
Shayokh
ShayokhOP4d ago
Both :] Along with Sass
13eck
13eck4d ago
If you're using BS, you're not…yeah, none of that is "raw CSS"
Shayokh
ShayokhOP4d ago
They are modifying parts of Bootstrap Using Sass
13eck
13eck4d ago
SASS isn't CSS. BS isn't raw CSS, it's a design lib
Shayokh
ShayokhOP4d ago
Ahh I see. Anyways thanks all for the help I will go make a new svg
ἔρως
ἔρως4d ago
i recommend that you use svg symbols and use currentColor for the fill
b1mind
b1mind4d ago
That solves none of this issue JSX is horrible imo and not a fan of Tailwind
ἔρως
ἔρως4d ago
it doesn't, but after the fixes, it adds a little bit of ease
Shayokh
ShayokhOP3d ago
Why do you not like JSX?
13eck
13eck3d ago
I can't speak for b1, but to me JSX is to HTML what Tailwind is to CSS: it's JavaScript for those afraid of learning how the front-end works. There are many different ways to create HTML in JS that lets you customize the element(s) made before adding them to the DOM that uses the actual HTML syntax. JSX requires you to write almost-HTML due to JS keywords being reserved—like you can't do <div class="container"> b/c class is a reserverd word! So you need to do className. And you need to enclose it all in one element to return because…why? They even give syntax for "we know this rule is dumb but we can't change it so here's a crutch". Or you could just write a string and do parentElement.innerHTML. Or document.createElement() and customize it like normal, then parentElement.appendChild(). The functionality that JSX provides already exists. And isn't tied specifically to React.
ἔρως
ἔρως3d ago
i also can't speak for b1mind, but jsx is a weak version of e4x, but for html and way less integrated into js the last point applied to e4x, and it just died due to lack of interest and some big security holes jsx doesn't seem to have security holes, but the god awful code that people write is just sad i love the trenary operator, but react people just use the living crap out of it for jsx and then when you mix typescript and get tsx, the code starts to look like butchered c++ meta programming

Did you find this page helpful?