I have a lightning icon in my lightning component. It is an icon of type standard and I want to change its color:
Component
<div class="slds-media__figure">
<lightning:icon iconName="standard:currency" class="cashAccountIcon" size="small"/>
</div>
Controller
.THIS.cashAccountIcon svg {
fill : red;
}
However, the color is not changing in the above code. Is that a problem with my code or we cannot change backgrounds of standard icons?
Best Answer
The
.THIS.myClass
, with the period attachingTHIS
andmyClass
tries to look for the root element and whether it hasmyClass
associated with it. Assuming your icon is not the root element in the component, try using.THIS .cashAccountIcon svg {
with a space between.THIS
and.cashAccountIcon
For what it's worth, if you use VS Code, you can hover over the
.THIS ...
line of code and see what kind of document structure it is trying to apply the CSS to.