<button class="btn--angle"><span class="btn__inner">An angle button</span></button>
<hr>
<button class="btn--angle"><span class="btn__inner">An angle button with a longer name just fails</span></button>
/**
* Button angle with pseudo-element
*/
.btn--angle {
--angle-width: 2rem;
--bg-color: lightseagreen;
--bg-color-hover: steelblue;
--duration: 300ms;
--easing: cubic-bezier(0.165, 0.840, 0.440, 1);
--padding-x: 1rem;
--padding-y: 1rem;
background-color: transparent;
color: black;
display: inline-block;
line-height: 1;
padding-right: var(--angle-width);
position: relative;
}
.btn--angle::before {
content: '';
border: 0 solid transparent;
border-bottom-width: calc(var(--angle-width) * 0.75);
border-top-width: calc(var(--angle-width) * 0.75);
border-left: var(--angle-width) solid var(--bg-color);
position: absolute;
right: 0;
top: 0;
transition: border-color var(--duration) var(--easing);
}
.btn--angle .btn__inner {
background-color: var(--bg-color);
display: block;
padding: var(--padding-y) var(--padding-x);
transition: background-color var(--duration) var(--easing);
}
.btn--angle:hover::before {
border-left-color: var(--bg-color-hover);
transition: border-color var(--duration) var(--easing);
}
.btn--angle:hover .btn__inner {
background-color: var(--bg-color-hover);
transition: background-color var(--duration) var(--easing);
}
/**
* demo styles
*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: ghostwhite;
font-family: system-ui, system, sans-serif;
line-height: 1.5;
max-width: 250px;
padding: 1rem;
}
button {
border: 0;
cursor: pointer;
font-family: system-ui, system, sans-serif;
font-weight: 600;
text-align: left;
}
hr {
border: 0;
margin: 2rem;
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.