<ul class="list">
<li class="list-item">
<input type="checkbox" class="hidden-box" id="first" checked/>
<label for="first" class="check--label">
<span class="check--label-box"></span>
<span class="check--label-text">First Checkbox</span>
</label>
</li>
<li class="list-item">
<input type="checkbox" class="hidden-box" id="second" />
<label for="second" class="check--label">
<span class="check--label-box"></span>
<span class="check--label-text">Second Checkbox</span>
</label>
</li>
<li class="list-item">
<input type="checkbox" class="hidden-box" id="third" />
<label for="third" class="check--label">
<span class="check--label-box"></span>
<span class="check--label-text">Third Checkbox</span>
</label>
</li>
</ul>
* {
box-sizing: border-box;
}
html, body {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: #1abc9c;
font-family: 'Roboto', sans-serif;
}
.list {
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
width: 80%;
max-width: 500px;
background-color: #fff;
border-radius: 6px;
box-shadow: 10px 10px 0 0 rgba(0,0,0,0.2);
list-style: none;
overflow: hidden;
.list-item {
margin: 0;
padding: 0;
border-bottom: 1px solid #ecf0f1;
position: relative;
&:last-child {
border: 0;
}
}
}
// hide the checkbox
.hidden-box {
position: absolute;
top: -9999px;
left: -9999px;
appearance: none;
opacity: 0;
}
.check--label {
font-size: 20px;
margin: 0;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
}
.check--label-box {
display: flex;
align-self: center;
position: relative;
height: 20px;
width: 20px;
margin: 0 20px;
border: 2px solid #3498db;
border-radius: 2px;
cursor: pointer;
}
.check--label-text {
display: flex;
align-self: center;
position: relative;
cursor: pointer;
padding: 20px;
border-left: 1px solid #ecf0f1;
&:after {
content: '';
display: block;
width: 0%;
height: 2px;
background-color: #000;
position: absolute;
top: 50%;
left: 7.5%;
transform: translateY(-50%);
transition: width 100ms ease-in-out;
}
}
// the magic
.hidden-box:checked + .check--label {
background-color: #F9F9F9;
.check--label-box {
background-color: #3498db;
&:after {
content: '';
display: block;
position: absolute;
top: -1px;
left: 4px;
width: 6px;
height: 12px;
border: solid #000;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
}
.check--label-text {
&:after {
width: 85%;
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.