I’m working on creating a CSS button with these specific requirements:
- Rectangular body with smoothly rounded corners.
- Triangular arrow tip on the right side.
- The arrow tip should have a fixed width of 20px, regardless of the
button’s overall width. - The button should be flexible to accommodate text of varying lengths
(including potential line breaks).
Here’s my current code. I’m using clip-path
to create the arrow shape on the right side of the button, setting the arrow tip to a fixed 20px width from the button’s 100% width.
To avoid text overlap with the arrow, I’ve adjusted the padding accordingly.
.cta-button {
display: inline-block;
padding: 10px 30px 10px 10px;
background-color: #004c97;
color: #ffffff;
font-family: Arial;
font-size: 14px;
text-align: center;
border: none;
cursor: pointer;
line-height: 1.2;
position: relative;
clip-path: polygon( 0 0
, calc(100% - 20px) 0
, 100% 50%
, calc(100% - 20px) 100%
, 0 100%);
border-radius: 10px;
}
This setup mostly achieves what I need, but there’s one issue: I can’t get the rounded corners effect on the arrow tip itself.
Normally, I would use the border-radius
property, but since it applies to the entire div
element, it doesn’t affect the shape created by clip-path
. This leaves only the left corners rounded.
I’ve also tried using an SVG path for a rounded-corner effect. However, with this approach, the arrow tip scales along with the button size, making it more acute as the button lengthens.
Is there a way to:
- Achieve smoothly rounded corners for the whole button, including the arrow tip, and
- Maintain a fixed width of 20px for the arrow tip, independent of the button’s overall length?
Any solutions or workarounds to accomplish both the fixed-size arrow tip and smooth rounded corners would be very helpful! Thank you.
2
Answers
If I’m not mistaken and I understand correctly what you want to achieve,
here it is:
Hope this fits the requirements.
This solution rounds every corner of the polygon clipping path, keeping the proportions of the arrow at the end regardless of character count (move the slider around to test it):
Related question and answer