Looking to create a 3D diagonal emboss button similar to the image below:
https://i.sstatic.net/43cSd.jpg
My initial idea is to incorporate shadow effects and then use two small triangles with ::before
and ::after
pseudo-elements to close the gap.
However, I've noticed that there is always a very slight misalignment of less than 1 pixel (as shown in the snippet below). To make coding easier, I've used different colors for distinction.
.button {
border: 1px solid red;
box-shadow: -10px 10px red;
display: inline-block; margin: 30px; position: relative; outline: none; font-size: 40px;
padding: 10px 30px; background-color: #333; font-weight: 700;
color: white; letter-spacing: 1px;
line-height: 1; text-transform: uppercase; text-align: center;
}
/* create triangle */
.button::before { content: ""; position: absolute;
top: -1px;
left: -11px;
width: 0; height: 0; font-size: 0; line-height: 0%; border-style: solid; border-color: transparent; border-width: 0 0 11px 11px; border-bottom-color: red; }
.button::after { content: ""; position: absolute;
right: -1px;
bottom: -11px;
width: 0; height: 0; font-size: 0; line-height: 0%; border-style: solid; border-color: transparent; border-width: 11px 11px 0 0; border-top-color: red; }
<a class="button">Gallery</a>
Is there a more efficient way to implement this design without using triangles and absolute positioning?