پیشنمایش زنده
کد HTML
<div class="radio">
<input
label="Yes"
type="radio"
id="male"
name="gender"
value="male"
checked=""
/>
<input label="No" type="radio" id="female" name="gender" value="female" />
<input
label="I hate making decisions 🤷🏻♂️"
type="radio"
id="other"
name="gender"
value="other"
/>
</div>
کد CSS
.radio {
background: #454857;
padding: 4px;
border-radius: 3px;
box-shadow: inset 0 0 0 3px rgba(35, 33, 45, 0.3),
0 0 0 3px rgba(185, 185, 185, 0.3);
position: relative;
}
.radio input {
width: auto;
height: 100%;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: none;
cursor: pointer;
border-radius: 2px;
padding: 4px 8px;
background: #454857;
color: #bdbdbdbd;
font-size: 14px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
transition: all 100ms linear;
}
.radio input:checked {
background-image: linear-gradient(180deg, #95d891, #74bbad);
color: #fff;
box-shadow: 0 1px 1px #0000002e;
text-shadow: 0 1px 0px #79485f7a;
-webkit-animation: rubberBand 1s both;
animation: rubberBand 1s both;
}
.radio input:before {
content: attr(label);
display: inline-block;
text-align: center;
width: 100%;
}
@-webkit-keyframes rubberBand {
0% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
30% {
-webkit-transform: scale3d(1.25, 0.75, 1);
transform: scale3d(1.25, 0.75, 1);
}
40% {
-webkit-transform: scale3d(0.75, 1.25, 1);
transform: scale3d(0.75, 1.25, 1);
}
50% {
-webkit-transform: scale3d(1.15, 0.85, 1);
transform: scale3d(1.15, 0.85, 1);
}
65% {
-webkit-transform: scale3d(0.95, 1.05, 1);
transform: scale3d(0.95, 1.05, 1);
}
75% {
-webkit-transform: scale3d(1.05, 0.95, 1);
transform: scale3d(1.05, 0.95, 1);
}
100% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}
@keyframes rubberBand {
0% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
30% {
-webkit-transform: scale3d(1.25, 0.75, 1);
transform: scale3d(1.25, 0.75, 1);
}
40% {
-webkit-transform: scale3d(0.75, 1.25, 1);
transform: scale3d(0.75, 1.25, 1);
}
50% {
-webkit-transform: scale3d(1.15, 0.85, 1);
transform: scale3d(1.15, 0.85, 1);
}
65% {
-webkit-transform: scale3d(0.95, 1.05, 1);
transform: scale3d(0.95, 1.05, 1);
}
75% {
-webkit-transform: scale3d(1.05, 0.95, 1);
transform: scale3d(1.05, 0.95, 1);
}
100% {
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
}
}