پیشنمایش زنده
کد HTML
<label class="btn-wrapper">
<input type="checkbox" class="toggle" />
<div class="btn">
<span class="btn-txt play">Play</span>
<span class="btn-txt playing">Playing</span>
<div class="dot"></div>
</div>
</label>
کد CSS
.btn-wrapper {
--width: 150px;
--height: 60px;
--padding: 8px;
--border-radius: 24px;
--dot-size: 8px;
--btn-color: #000000;
--hue: 14deg;
--animation-duration: 1.2s;
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: var(--width);
height: var(--height);
border-radius: var(--border-radius);
background-color: #00000008;
box-shadow:
1px 1px 2px 0 #fffd,
2px 2px 2px #0001 inset,
2px 2px 4px #0001 inset,
2px 2px 8px #0001 inset;
perspective: 150px;
cursor: pointer;
user-select: none;
transition:
box-shadow 0.05s linear,
transform 0.05s linear;
}
.toggle {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
z-index: 5;
cursor: pointer;
}
.btn {
display: flex;
align-items: center;
justify-content: start;
gap: 0.25em;
text-align: left;
padding: 0 var(--height) 0 calc(var(--padding) * 2);
width: calc(100% - 2 * var(--padding));
height: calc(100% - 2 * var(--padding));
border-radius: calc(var(--border-radius) - var(--padding));
border: none;
cursor: pointer;
background: linear-gradient(#fff2, #0001), var(--btn-color);
box-shadow:
1px 1px 2px -1px #fff inset,
0 2px 1px #00000010,
0 4px 2px #00000010,
0 8px 4px #00000010,
0 16px 8px #00000010,
0 32px 16px #00000010;
transition:
transform 0.15s cubic-bezier(0.25, 1.5, 0.5, 1.5),
box-shadow 0.15s ease,
filter 0.15s ease;
z-index: 2;
}
.btn-txt {
position: absolute;
font-family: "Montserrat", "Manrope", sans-serif;
font-weight: 500;
font-size: 16px;
color: rgba(255, 255, 255, 0.616);
background-image: linear-gradient(#000a, #555);
background-clip: text;
filter: drop-shadow(0 1px 0px #fff) drop-shadow(0 -1px 0px #0005);
transition: opacity 0.2s ease;
}
.playing {
opacity: 0;
}
.toggle:checked ~ .btn .play {
opacity: 0;
}
.toggle:checked ~ .btn .playing {
opacity: 1;
}
.dot {
position: absolute;
top: 50%;
right: calc(var(--height) / 2 - var(--padding) / 2);
width: var(--dot-size);
aspect-ratio: 1/1;
border-radius: 50%;
background-color: hsla(var(--hue), 0%, 50%, 0.1);
border: 1px solid hsla(var(--hue), 0%, 60%, 0.6);
box-shadow:
1px 1px 2px -1px #fffe inset,
0 2px 1px #00000010,
0 4px 2px #00000010,
0 8px 4px #00000010;
pointer-events: none;
z-index: 3;
transform: translateY(-50%);
transition: all 0.15s ease;
}
@keyframes pulse {
0%,
100% {
transform: scale(0.8) translateY(-50%);
opacity: 0.4;
}
50% {
transform: scale(1.3) translateY(-50%);
opacity: 1;
}
}
.toggle:checked ~ .btn .dot {
animation: pulse var(--animation-duration) ease-in-out infinite;
background-color: hsl(var(--hue), 90%, 50%);
box-shadow:
0 0 6px 1px hsl(var(--hue), 100%, 50%),
0 0 20px 5px hsl(var(--hue), 100%, 60%, 0.4);
}
/* ----------------- Hover & Tactile Press ----------------- */
.btn-wrapper:hover .btn,
.btn-wrapper:focus-within .btn {
transform: translate3d(0, -2px, 2px);
filter: drop-shadow(
var(--padding) 0 var(--padding) hsla(var(--hue), 70%, 60%, 0.6)
);
}
.btn-wrapper:active .btn {
transform: translate3d(0, 2px, -2px);
box-shadow:
1px 1px 2px 0 #fff,
2px 2px 2px #0001 inset,
2px 2px 4px #0001 inset,
2px 2px 8px #0001 inset,
0 0 32px 2px hsla(var(--hue), 50%, 50%, 0.5) inset;
}