源码:
<div class="container">
<!-- TITLE -->
<span class="title">
css Material Design checkbox
</span>
<!-- CHECKBOXES -->
<div class="checkbox">
<input type="checkbox" id="checkbox1" class="checkbox__input" checked>
<label for="checkbox1" class="checkbox__label">Checkbox 1</label>
</div><br>
<div class="checkbox">
<input type="checkbox" id="checkbox2" class="checkbox__input">
<label for="checkbox2" class="checkbox__label">Checkbox 2</label>
</div><br>
<div class="checkbox">
<input type="checkbox" id="checkbox3" class="checkbox__input">
<label for="checkbox3" class="checkbox__label">Checkbox 3</label>
</div><br>
</div>
<style>
body, html {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Roboto, sans-serif;
width: 100%;
background: #fafafa;
color: #757575;
}
*, *:before, *:after {
box-sizing: inherit;
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.title {
display: block;
margin: 0 0 20px;
font-size: 24px;
text-transform: uppercase;
}
.checkbox {
display: inline-block;
position: relative;
margin: 0 0 10px;
font-size: 16px;
line-height: 24px;
}
.checkbox__input {
position: absolute;
top: 4px;
left: 0;
width: 16px;
height: 16px;
opacity: 0;
z-index: 0;
}
.checkbox__label {
display: block;
padding: 0 0 0 24px;
cursor: pointer;
}
.checkbox__label:before {
content: '';
position: absolute;
top: 4px;
left: 0;
width: 16px;
height: 16px;
background-color: transparent;
border: 2px solid rgba(0, 0, 0, 0.54);
border-radius: 2px;
z-index: 1;
transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition-property: background-color, border-color;
}
.checkbox__label:after {
content: '';
position: absolute;
top: 5px;
left: 5px;
width: 6px;
height: 12px;
border-bottom: 2px solid transparent;
border-right: 2px solid transparent;
transform: rotate(45deg);
z-index: 2;
transition: border-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.checkbox__input:checked + .checkbox__label:before {
background-color: #3f51b5;
border-color: #3f51b5;
}
.checkbox__input:checked + .checkbox__label:after {
border-color: #fff;
}
</style>