پیشنمایش زنده
کد HTML
<article class="keycap">
<aside class="letter">
Enter
<svg fill="none" viewBox="0 0 24 24" class="enter-icon">
<path
stroke-linejoin="round"
stroke-linecap="round"
stroke-width="2"
stroke="white"
d="M3 12L9 18M3 12L9 6M3 12H21"
></path>
</svg>
</aside>
</article>
کد CSS
.keycap {
position: relative;
display: inline-block;
width: 130px;
height: 80px;
border-radius: 10px;
background: linear-gradient(180deg, #282828, #202020);
box-shadow:
inset -8px 0 8px rgba(0, 0, 0, 0.15),
inset 0 -8px 8px rgba(0, 0, 0, 0.25),
0 0 0 2px rgba(0, 0, 0, 0.75),
10px 20px 25px rgba(0, 0, 0, 0.4);
overflow: hidden;
transition:
transform 0.1s ease-in-out,
box-shadow 0.1s ease-in;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.keycap .letter {
position: absolute;
left: 12px;
top: 12px;
color: #e9e9e9;
font-size: 16px;
display: flex;
align-items: center;
gap: 8px;
transition: transform 0.1s ease-in-out;
}
.keycap .enter-icon {
width: 20px;
height: 20px;
stroke: #e9e9e9;
}
.keycap::before {
content: "";
position: absolute;
top: 3px;
left: 4px;
bottom: 14px;
right: 12px;
background: linear-gradient(90deg, #232323, #4a4a4a);
border-radius: 10px;
box-shadow:
-10px -10px 10px rgba(255, 255, 255, 0.25),
10px 5px 10px rgba(0, 0, 0, 0.15);
border-left: 1px solid #0004;
border-bottom: 1px solid #0004;
border-top: 1px solid #0009;
transition: all 0.1s ease-in-out;
}
.keycap:active {
transform: translateY(2px);
box-shadow:
inset -4px 0 4px rgba(0, 0, 0, 0.1),
inset 0 -4px 4px rgba(0, 0, 0, 0.15),
0 0 0 2px rgba(0, 0, 0, 0.5),
5px 10px 15px rgba(0, 0, 0, 0.3);
}
.keycap:active::before {
top: 5px;
left: 5px;
bottom: 11px;
right: 11px;
box-shadow:
-5px -5px 5px rgba(255, 255, 255, 0.15),
5px 3px 5px rgba(0, 0, 0, 0.1);
}
.keycap:active .letter {
transform: translateY(1px);
}