پیشنمایش زنده
کد HTML
<button class="u-btn" type="button" aria-label="Click me">
<div class="u-btn__top">Click Me!</div>
<div class="u-btn__bottom" aria-hidden="true"></div>
</button>
کد CSS
.u-btn {
width: 140px;
height: 50px;
position: relative;
background: none;
border: none;
padding: 0;
margin: 0;
cursor: pointer;
font-family:
"Poppins",
system-ui,
-apple-system,
"Segoe UI",
Roboto,
"Helvetica Neue",
Arial;
-webkit-tap-highlight-color: transparent;
}
/* Top face */
.u-btn__top {
width: 100%;
height: 100%;
background: rgb(255, 255, 238);
font-size: 16px;
color: rgb(36, 38, 34);
display: flex;
align-items: center;
justify-content: center;
border-radius: 12px; /* replaced mm with px for consistency */
outline: 2px solid rgb(36, 38, 34);
transition:
transform 0.2s ease,
box-shadow 0.2s ease;
position: relative;
overflow: hidden;
box-sizing: border-box;
}
/* Bottom shadow/surface */
.u-btn__bottom {
position: absolute;
width: 100%;
height: 100%;
background: rgb(229, 229, 199);
top: 10px;
left: 0;
border-radius: 12px;
outline: 2px solid rgb(36, 38, 34);
z-index: -1;
box-sizing: border-box;
}
/* small vertical posts on the base */
.u-btn__bottom::before,
.u-btn__bottom::after {
position: absolute;
content: "";
width: 2px;
height: 9px;
background: rgb(36, 38, 34);
bottom: 0;
}
.u-btn__bottom::before {
left: 15%;
}
.u-btn__bottom::after {
left: 85%;
}
/* pressed state: move the top face down */
.u-btn:active .u-btn__top {
transform: translateY(10px);
}
/* extra shading layer behind the base */
.u-btn::before {
position: absolute;
content: "";
width: calc(100% + 2px);
height: 100%;
background: rgb(140, 140, 140);
top: 14px;
left: -1px;
border-radius: 12px;
outline: 2px solid rgb(36, 38, 34);
z-index: -2;
}
/* gloss on the top face */
.u-btn__top::before {
position: absolute;
content: "";
width: 15px;
height: 100%;
background: rgba(0, 0, 0, 0.1);
transform: skewX(30deg);
left: -20px;
transition: left 0.25s ease;
pointer-events: none;
}
/* animate gloss moving across when pressed */
.u-btn:active .u-btn__top::before {
left: calc(100% + 20px);
}
/* keyboard-focus visible state for accessibility */
.u-btn:focus-visible .u-btn__top {
box-shadow: 0 0 0 3px rgba(36, 38, 34, 0.12);
outline: none;
}