I made a fancy custom checkbox that animates a gradient in/out when (un)checked. How can I make the checkbox border a gradient, as well? The border gradient should match the fill gradient just like the solid-colored fancy checkboxes.
I tried both the wrapping and pseudo-element methods described here: https://css-tricks.com/gradient-borders-in-css. However these methods:
- Don't seem to work well with checkbox inputs (like integrating with the input focus outline.)
- Interfere with the pseudo-element used to animate the checkbox gradient.
/*Based on: https://moderncss.dev/pure-css-custom-checkbox-style/ */
input[type='checkbox'] {
appearance: none;
background-color: #fff !important;
display: inline-grid;
place-content: center;
color: purple;
border-color: purple;
}
input[type='checkbox']::before {
content: '';
width: inherit;
height: inherit;
border-radius: inherit;
transform: scale(0);
transition: 500ms transform ease-in-out;
background: purple;
}
input[type='checkbox']:checked::before {
transform: scale(1);
transition: 500ms transform ease-in-out;
background: purple;
}
input[type='checkbox'].gradient-bg::before {
background: linear-gradient(45deg, blue 20%, red 80%);
}
<div class=container>
<input type="checkbox" class="gradient-bg" checked />
<input type="checkbox" class="gradient-bg" />
<input type="checkbox" checked />
<input type="checkbox" />
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">