Custom checkboxes CSS Animation

Custom checkboxes CSS Animation

by Сергей Тарасевич

HTML

<!-- inspired by https://dribbble.com/shots/1927803-Toggle -->

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<form action="">
  <label>
    <input type="checkbox" />
    <div><i class="fa fa-dribbble"></i></div>
  </label>

  <label>
    <input type="checkbox" checked />
    <div><i class="fa fa-jsfiddle"></i></div>
  </label>

  <label>
    <input type="checkbox" />
    <div><i class="fa fa-github"></i></div>
  </label>

  <label>
    <input type="checkbox" />
    <div><i class="fa fa-twitter"></i></div>
  </label>
</form>

CSS

body {
    padding: 40px;
    text-align: center;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    background: #fff;
}

label input[type="checkbox"] {
    display: none;
}

label input[type="checkbox"] + div {
    height: 50px;
    width: 60px;
    border: solid 1px #F0F4F5;
    background: #F0F4F5;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    margin: 10px;
    display: inline-block;
    text-align: center;
    line-height: 60px;
    color: #BEC7C7;
    @include transition(all 0.3s);

}
label input[type="checkbox"] + div i.fa {
        font-size: 1.6rem;
    }
                
label input[type="checkbox"] + div:before {
        content: " ";
        display: block;
        opacity: 0;
        height: 26px;
        width: 26px;
        position: absolute;
        top: -15px;
        right: -15px;
        border-radius: 100%;
        background: #00DC9D;
        border: solid 3px #fff;
    }
        
label input[type="checkbox"] + div:after {
        font-family: FontAwesome;
        content: "\f00c";
        display: block;
        opacity: 0;
        height: 32px;
        width: 32px;
        position: absolute;
        top: -15px;
        right: -15px;
        color: #fff;
        line-height: 32px;
        text-align: center;       
    }

label input[type="checkbox"]:checked + div {
    border: solid 1px #E7EBEC;
    background: transparent;
    color: #444;

}
label input[type="checkbox"]:checked + div:before {
        opacity: 1;
        @include animation(show-a 0.3s);
    }
        
label input[type="checkbox"]:checked + div:after {
        opacity: 1;
        @include animation(show-b 0.3s);
    }