单选按钮选中动效

交互动画 2026/05/31 15:25

HTML代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<div class="container">
  <div class="radio-input">
    <label class="label">
      <div class="back-side"></div>
      <input type="radio" id="value-1" name="value-radio" value="value-1" checked />
      <span class="text">play</span>
      <span class="bottom-line"></span>
    </label>

    <label class="label">
      <div class="back-side"></div>
      <input type="radio" id="value-2" name="value-radio" value="value-2" />
      <span class="text">stop</span>
      <span class="bottom-line"></span>
    </label>

    <label class="label">
      <div class="back-side"></div>
      <input type="radio" id="value-3" name="value-radio" value="value-3" />
      <span class="text">again</span>
      <span class="bottom-line"></span>
    </label>
  </div>
</div>

CSS代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
.container {
  width: 100%;
  height: 320px;
  background: #1e1e1e;
  padding-top: 100px;
}

.radio-input {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: black;
  padding: 6px;
  border-radius: 8px;
  overflow: hidden;
  height: 94px;
  width: 232px;
  margin: 0 auto;
}

.radio-input input {
  display: none;
}

.radio-input .label {
  width: 70px;
  height: 80px;
  background-color: #2a2a2a;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px;
  border-top: 1px solid #383838;
  transition: all 0.1s linear;
  position: relative;
  z-index: 2;
}

.label .back-side {
  position: absolute;
  top: -10px;
  left: 0px;
  background-color: #2a2a2a;
  border-radius: 4px 4px 2px 2px;
  width: 100%;
  height: 14px;
  box-shadow:
    inset 0 5px 3px 1px rgba(0, 0, 0, 0.5),
    inset 0px -5px 2px 0px rgba(56, 163, 224, 0.1);
  transform: perspective(300px) rotateX(50deg);
  z-index: 1;
  opacity: 0;
  transition: all 0.1s linear;
}

.label:has(input[type="radio"]:checked) .back-side {
  opacity: 1;
}

.label:has(input[type="radio"]:checked) {
  transform: perspective(200px) rotateX(-18deg);
  transform-origin: 50% 40%;
  box-shadow: inset 0px -20px 15px 0px rgba(0, 0, 0, 0.5);
  border-top: 1px solid #2589c362;
  margin-top: 6px;
  border-radius: 0 0 4px 4px;
}

.label .text {
  color: black;
  font-size: 15px;
  line-height: 12px;
  padding: 0px;
  font-weight: 800;
  text-transform: uppercase;
  transition: all 0.1s linear;
  text-shadow: -1px -1px 1px rgb(224, 224, 224, 0.1);
}

.label input[type="radio"]:checked + .text {
  color: #258ac3;
  text-shadow:
    0px 0px 8px rgb(37, 138, 195),
    1px 1px 2px rgb(0, 0, 0, 1);
}

.label .bottom-line {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background-color: #2a2a2a;
  box-shadow: 0 0 3px 0px rgb(19, 19, 19);
  border-top: 1px solid #383838;
  transition: all 0.1s linear;
}

.label:has(input[type="radio"]:checked) .bottom-line {
  background-color: #1a1a1a;
  border-top: 1px solid #258ac340;
}