پیشنمایش زنده
کد HTML
<div class="radio-inputs">
<label class="radio">
<input checked="" name="radio" type="radio" />
<span class="name">First</span>
</label>
<label class="radio">
<input name="radio" type="radio" />
<span class="name">Second</span>
</label>
<label class="radio">
<input name="radio" type="radio" />
<span class="name">Third</span>
</label>
</div>
کد CSS
.radio-inputs {
position: relative;
display: flex;
flex-wrap: wrap;
border-radius: 1rem;
background: linear-gradient(145deg, #e6e6e6, #ffffff);
box-sizing: border-box;
box-shadow:
5px 5px 15px rgba(0, 0, 0, 0.15),
-5px -5px 15px rgba(255, 255, 255, 0.8);
padding: 0.5rem;
width: 300px;
font-size: 14px;
gap: 0.5rem;
}
.radio-inputs .radio {
flex: 1 1 auto;
text-align: center;
position: relative;
}
.radio-inputs .radio input {
display: none;
}
.radio-inputs .radio .name {
display: flex;
cursor: pointer;
align-items: center;
justify-content: center;
border-radius: 0.7rem;
border: none;
padding: 0.7rem 0;
color: #2d3748;
font-weight: 500;
font-family: inherit;
background: linear-gradient(145deg, #ffffff, #e6e6e6);
box-shadow:
3px 3px 6px rgba(0, 0, 0, 0.1),
-3px -3px 6px rgba(255, 255, 255, 0.7);
transition: all 0.2s ease;
overflow: hidden;
}
.radio-inputs .radio input:checked + .name {
background: linear-gradient(145deg, #3b82f6, #2563eb);
color: white;
font-weight: 600;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
box-shadow:
inset 2px 2px 5px rgba(0, 0, 0, 0.2),
inset -2px -2px 5px rgba(255, 255, 255, 0.1),
3px 3px 8px rgba(59, 130, 246, 0.3);
transform: translateY(2px);
}
/* Hover effect */
.radio-inputs .radio:hover .name {
background: linear-gradient(145deg, #f0f0f0, #ffffff);
transform: translateY(-1px);
box-shadow:
4px 4px 8px rgba(0, 0, 0, 0.1),
-4px -4px 8px rgba(255, 255, 255, 0.8);
}
.radio-inputs .radio:hover input:checked + .name {
transform: translateY(1px);
}
/* Animation */
.radio-inputs .radio input:checked + .name {
animation: select 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Particles */
.radio-inputs .radio .name::before,
.radio-inputs .radio .name::after {
content: "";
position: absolute;
width: 6px;
height: 6px;
border-radius: 50%;
opacity: 0;
pointer-events: none;
}
.radio-inputs .radio input:checked + .name::before,
.radio-inputs .radio input:checked + .name::after {
animation: particles 0.8s ease-out forwards;
}
.radio-inputs .radio .name::before {
background: #60a5fa;
box-shadow: 0 0 6px #60a5fa;
top: -10px;
left: 50%;
transform: translateX(-50%);
}
.radio-inputs .radio .name::after {
background: #93c5fd;
box-shadow: 0 0 8px #93c5fd;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
}
/* Sparkles */
.radio-inputs .radio .name::after {
content: "";
position: absolute;
inset: 0;
z-index: -1;
background: radial-gradient(
circle at var(--x, 50%) var(--y, 50%),
rgba(59, 130, 246, 0.3) 0%,
transparent 50%
);
opacity: 0;
transition: opacity 0.3s;
}
.radio-inputs .radio input:checked + .name::after {
opacity: 1;
animation: sparkle-bg 1s ease-out forwards;
}
/* Multiple particles */
.radio-inputs .radio input:checked + .name {
overflow: visible;
}
.radio-inputs .radio input:checked + .name::before {
box-shadow:
0 0 6px #60a5fa,
10px -10px 0 #60a5fa,
-10px -10px 0 #60a5fa;
animation: multi-particles-top 0.8s ease-out forwards;
}
.radio-inputs .radio input:checked + .name::after {
box-shadow:
0 0 8px #93c5fd,
10px 10px 0 #93c5fd,
-10px 10px 0 #93c5fd;
animation: multi-particles-bottom 0.8s ease-out forwards;
}
@keyframes select {
0% {
transform: scale(0.95) translateY(2px);
}
50% {
transform: scale(1.05) translateY(-1px);
}
100% {
transform: scale(1) translateY(2px);
}
}
@keyframes multi-particles-top {
0% {
opacity: 1;
transform: translateX(-50%) translateY(0) scale(1);
}
40% {
opacity: 0.8;
}
100% {
opacity: 0;
transform: translateX(-50%) translateY(-20px) scale(0);
box-shadow:
0 0 6px transparent,
20px -20px 0 transparent,
-20px -20px 0 transparent;
}
}
@keyframes multi-particles-bottom {
0% {
opacity: 1;
transform: translateX(-50%) translateY(0) scale(1);
}
40% {
opacity: 0.8;
}
100% {
opacity: 0;
transform: translateX(-50%) translateY(20px) scale(0);
box-shadow:
0 0 8px transparent,
20px 20px 0 transparent,
-20px 20px 0 transparent;
}
}
@keyframes sparkle-bg {
0% {
opacity: 0;
transform: scale(0.2);
}
50% {
opacity: 1;
}
100% {
opacity: 0;
transform: scale(2);
}
}
/* Ripple effect */
.radio-inputs .radio .name::before {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
background: radial-gradient(
circle at var(--x, 50%) var(--y, 50%),
rgba(255, 255, 255, 0.5) 0%,
transparent 50%
);
opacity: 0;
transition: opacity 0.3s;
}
.radio-inputs .radio input:checked + .name::before {
animation: ripple 0.8s ease-out;
}
@keyframes ripple {
0% {
opacity: 1;
transform: scale(0.2);
}
50% {
opacity: 0.5;
}
100% {
opacity: 0;
transform: scale(2.5);
}
}
/* Glowing border */
.radio-inputs .radio input:checked + .name {
position: relative;
}
.radio-inputs .radio input:checked + .name::after {
content: "";
position: absolute;
inset: -2px;
border-radius: inherit;
background: linear-gradient(
45deg,
rgba(59, 130, 246, 0.5),
rgba(37, 99, 235, 0.5)
);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
animation: border-glow 1.5s ease-in-out infinite alternate;
}
@keyframes border-glow {
0% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}