Search code examples
cssbootstrap-4twitter-bootstrap-4

Bootstrap 4 cursor for custom-control in state disabled


I need other cursor for disabled custom-control elements (checkbox, radiobutton)

This style don't work:

.custom-control-input:disabled ~ .custom-control-label::before {
    cursor: not-allowed;
}

Solution

  • For disabled custom-control elements in Bootstrap 4 (checkbox, radio button), you need the following selector css rule/selector:

    .custom-control-input:disabled ~ .custom-control-label {
        cursor: not-allowed;
    }
    

    And if you wanted the custom cursor style only for the actual checkbox/radio button but not for the label (not recommended in this case), then you'd need this rule:

    .custom-control-input:disabled ~ .custom-control-label::after {
        cursor: not-allowed;
    }
    

    Click "run code snippet" below to see it working:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        
    <style>
    .custom-control-input:disabled~.custom-control-label {
        cursor: not-allowed;
    }
    </style>
    
    <form class="m-3">
        <div class="custom-control custom-radio custom-control-inline">
            <input type="radio" id="customRadioInline1" name="customRadioInline1" class="custom-control-input">
            <label class="custom-control-label" for="customRadioInline1">This custom radio is OK</label>
        </div>
        <div class="custom-control custom-radio custom-control-inline">
            <input type="radio" id="customRadioInline2" name="customRadioInline1" class="custom-control-input" disabled>
            <label class="custom-control-label" for="customRadioInline2">This one is disabled</label>
        </div>
        
        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="customCheck1">
            <label class="custom-control-label" for="customCheck1">This custom checkbox is OK</label>
        </div>
        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="customCheck2">
            <label class="custom-control-label" for="customCheck2">OK too</label>
        </div>
        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="customCheckDisabled" disabled>
            <label class="custom-control-label" for="customCheckDisabled">This custom checkbox is disabled</label>
        </div>
        
    </form>