I want to change the color of my checkbox in lightning
I have the following piece of code in my cmp
<lightning:input type="checkbox" label="P"
class="{!(v.isPVisible == true) ? 'selected' : ''}"
onchange="{!c.change}"/>
and the following in css
.THIS .selected{
background-color: #EEE;
}
the problem here is that, I want to change the color of the checkbox, (where the tick mark comes up), not the checkbox label. By the above code , the label background color gets changed
Best Answer
The
<lightning:input type="checkbox"
inherits the styling and markup from the checkbox as shown in the Lightning Design System's Checkbox Blueprint.So you are trying to change the color of the square which is
<span class="slds-checkbox_faux"></span>
Changing the background color of the square:
You need to add just one more selector,
.slds-checkbox_faux
to the CSS class that you have already written.And it will change the background color of just the square part of the checkbox.
Changing the color of the tick mark:
You can use the
:after
selector for the.slds-checkbox_faux
CSS classAnd it will change the color of the tick mark
I hope this helps! :)