Skip to content

Instantly share code, notes, and snippets.

@maxdenaro
Last active December 25, 2020 13:51
Show Gist options
  • Save maxdenaro/a1a3b68eacb57f1b7ab5c90ee21b29f7 to your computer and use it in GitHub Desktop.
Save maxdenaro/a1a3b68eacb57f1b7ab5c90ee21b29f7 to your computer and use it in GitHub Desktop.
Custom policy checkbox
.policy-checkbox input {
display: none;
}
.policy-checkbox span {
position: relative;
display: inline-block;
padding-left: 30px;
}
.policy-checkbox span::before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 20px;
height: 20px;
border: 1px solid #000;
border-radius: 100%;
}
.policy-checkbox span::after {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 20px;
height: 20px;
background-color: #000;
border: 1px solid #000;
border-radius: 100%;
opacity: 0;
transition: all 0.15s;
}
.policy-checkbox span.checked::after {
opacity: 1;
transition: all 0.15s;
}
<label>
<input type="checkbox">
<span>Agree with this policy</span>
</label>
$('.policy-checkbox').click(function(){
if ($(this).find('input').prop('checked') == true) {
$(this).find('span').addClass('checked');
} else {
$(this).find('span').removeClass('checked');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment