Firstly, I have searched SO for similar questions and there are many but none which have the exact requirements below.
I am trying to create the button below using pure css.
It has the following requirements.
- It has a 1px border with a horizontal gradient.
- It must be transparent.
- It must have rounded corners
- It will have a cut-out of the border which is also transparent.
- It must be variable width and height
- It should work in all modern browsers (not IE)
I have created a Code Sandbox which gets all of it right except the border-radius. I have used a polygon clip-path for the cut out and used border-image for the gradient which is why the border-radius doesn't work.
body {
font-family: sans-serif;
background-color: #232837;
}
.button {
cursor: pointer;
display: inline-block;
height: 40px;
line-height: 40px;
padding: 0 10px;
color: white;
background-color: transparent;
border: solid 1px;
border-radius: 6px;
border-image: linear-gradient(to left, #743ad5 0%, #d53a9d 100%);
border-image-slice: 1;
clip-path: polygon(0 0, 12px 0, 12px 1px, 24px 1px, 24px 0, 100% 0, 100% 100%, 0 100%);
}
<div style="padding:40px;">
<a class="button">This is a button</a>
</div>
https://codesandbox.io/s/kw9p9k5073
I have managed to avoid using svgs so far as I don't really understand them well enough to implement a solution properly but if I have to go down that path I will.
Any advice would be very much appreciated.