Reputation: 78
I have a custom checkbox and I rounded the corners with border_radius
and I want the inner section to be also rounded.
Images side-by-side: checkbox when unchecked and checkbox when checked
My CSS code:
.checkbox {
text-align: center;
appearance: none;
height: 31px;
width: 31px;
padding: 10px;
margin-right: 12px;
border: 3px solid #D6D6D6;
border-radius: 50%;
cursor: pointer;
background: linear-gradient(90deg, #F2F2F2 50%, #F2F2F2 50%);
background-repeat: no-repeat;
background-position: center;
background-size: 15px 15px;
}
.checkbox:checked {
background: linear-gradient(90deg, black 50%, black 50%);
background-repeat: no-repeat;
background-position: center;
background-size: 15px 15px;
}
Upvotes: 1
Views: 845
Reputation: 273750
Rely on background-clip
.checkbox {
text-align: center;
appearance: none;
height: 31px;
width: 31px;
padding: 6px; /* adjust this to control the space between border and background */
margin-right: 12px;
border: 3px solid #D6D6D6;
border-radius: 50%;
cursor: pointer;
background-color: #f2f2f2;
background-clip: content-box;
box-sizing:border-box;
}
.checkbox:checked {
background-color: black;
}
<input type="checkbox" class="checkbox" />
Upvotes: 0
Reputation: 5084
You need to use radial-gradient()
to make it rounded.
.checkbox {
text-align: center;
appearance: none;
height: 31px;
width: 31px;
padding: 10px;
margin-right: 12px;
border: 3px solid #D6D6D6;
border-radius: 50%;
cursor: pointer;
background: radial-gradient(circle at center, #f2f2f2 50%, transparent 50%);
background-repeat: no-repeat;
background-position: center;
background-size: 15px 15px;
}
.checkbox:checked{
background: radial-gradient(circle at center, black 50%, transparent 50%);
background-repeat: no-repeat;
background-position: center;
background-size: 15px 15px;
}
<input type="checkbox" class="checkbox" />
Upvotes: 2