[SalesForce] Change backgroud color of a checkbox

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>

Edited the answer to add the step to change the color of the tick mark as well

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.

.THIS .selected .slds-checkbox_faux{
background: #EEE;
}

And it will change the background color of just the square part of the checkbox. enter image description here

Changing the color of the tick mark:

You can use the :after selector for the .slds-checkbox_faux CSS class

.THIS .selected .slds-checkbox_faux:after{
border-bottom: 2px solid rgb(75, 202, 129) !important;
border-left: 2px solid rgb(75, 202, 129) !important;
}

And it will change the color of the tick mark enter image description here

I hope this helps! :)