Create Elongated Hexagonal Buttons with CSS (Single Element Solution)
In the realm of button design, the elongated hexagon shape often catches the eye. While typically achieved using multiple elements, is it possible to create such a button using only one?
The answer is yes! Here's a creative solution to achieve this unique design:
Building the Base Shape
Achieving the Tilt Effect
Positioning the Elements
Emphasizing with Borders and Colors
Interactive Effects (Optional)
Code Example
/* General Button Style */ .button { position: relative; display: block; background: transparent; width: 300px; height: 80px; line-height: 80px; text-align: center; font-size: 20px; text-decoration: none; text-transform: uppercase; color: #e04e5e; margin: 40px auto; font-family: Helvetica, Arial, sans-serif; box-sizing: border-box; } .button:before, .button:after { position: absolute; content: ''; width: 300px; left: 0px; height: 34px; z-index: -1; } .button:before { transform: perspective(15px) rotateX(3deg); } .button:after { top: 40px; transform: perspective(15px) rotateX(-3deg); } /* Button Border Style */ .button.border:before, .button.border:after { border: 4px solid #e04e5e; } .button.border:before { border-bottom: none; /* to prevent the border-line showing up in the middle of the shape */ } .button.border:after { border-top: none; /* to prevent the border-line showing up in the middle of the shape */ } /* Button hover styles */ .button.border:hover:before, .button.border:hover:after { background: #e04e5e; } .button.border:hover { color: #fff; }
<a href="#" class="button ribbon-outset border">Click me!</a>
By leveraging this ingenious approach, you can effortlessly create captivating elongated hexagonal buttons using just one element. This technique adds a touch of elegance and uniqueness to any user interface.
The above is the detailed content of Can a Single CSS Element Create an Elongated Hexagonal Button?. For more information, please follow other related articles on the PHP Chinese website!