Last active
          August 29, 2015 14:15 
        
      - 
      
 - 
        
Save kPOWz/758e38b4fd32700bcd0c to your computer and use it in GitHub Desktop.  
    LESS mixin produces custom, cross-browser CSS checkbox for use with TWBS. Requires accessibility attributes on view.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Custom checkbox | |
| // | |
| // Requires checkbox type input with sibling label having the 'for' attribute | |
| // Relies on TWBS label display setting of 'display: inline-block;' | |
| // The label appears as the checkbox, while the real/orginal checkbox isn't displayed | |
| // Unicode is used for checkmark representation | |
| .input-checkbox-variant(@color; @background; @border; @size) | |
| when (get-unit(@size) = rem), (get-unit(@size) = em){ | |
| input[type='checkbox']{display: none;} | |
| input[type='checkbox'] label{ | |
| padding-left: 0; /* overrides TWBS default */ | |
| vertical-align: middle; | |
| } | |
| input[type='checkbox'] + label{ | |
| height: @size; | |
| width: @size; | |
| border: 1px solid @border; | |
| background: @background; | |
| } | |
| input[type='checkbox'] + label::before{ | |
| position: relative; | |
| @strip: unit(@size); | |
| @increment: ((@strip + 1) * -1); | |
| top: unit(@increment, px); /* change or remote calculation */ | |
| right: unit(@increment, px); /*remove*/ | |
| content: ""; | |
| } | |
| input[type='checkbox']:checked + label::before{ | |
| color: @color; | |
| font-size: @size; | |
| content: "\2713"; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | .custom .checkbox{ | |
| .input-checkbox-variant(@color-custom; @background-custom; @border-custom; @size-checkbox); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!-- --> | |
| <form class='custom'> | |
| <div class="form-group"> | |
| <label for="exampleInputEmail1">Email address</label> | |
| <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email"> | |
| </div> | |
| <div class='checkbox'> | |
| <input id="checkbox-1" type="checkbox" /> | |
| <label id="checkbox-1-custom" for="checkbox-1" aria-checked="false" role='checkbox' tabindex="0"></label> | |
| <label id='yes' role="label" for="checkbox-1-custom">Remember me next time</label> | |
| </div> | |
| </form> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment