JSFiddle - React, Tailwind, and code Playground
HTML
<button class="button back">
<svg><path d="M2,2 h12 l8,15 l-8,15 H2 V2 Z"/></svg>
Back with a long text
</button>
<button class="button forward">
<svg><path d="M2,2 h12 l8,15 l-8,15 H2 V2 Z"/></svg>
Forward
</button>
<a class="button back" href="#">
<svg><path d="M2,2 h12 l8,15 l-8,15 H2 V2 Z"/></svg>
Back
</a>
CSS
* {
font-family: inherit;
font-size: 100%;
line-height: 1;
vertical-align: baseline;
padding: 0;
margin: 0;
}
html {
font-family: sans-serif;
padding: 1em;
}
.button {
text-decoration: none;
line-height: 1.2;
background-color: transparent;
position: relative;
padding: .4em 1em .6em;
border: none;
}
.button.back { padding-left: 1.25em }
.button.forward { padding-right: 1.25em }
.button svg {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.button.back svg { transform: scale(-1, 1) }
svg {
fill: none;
stroke: currentColor;
stroke-width: 2;
}
JavaScript
(function( nodes ){
for ( var i = 0, total = nodes.length; i < total; ++i ){
var path = nodes[i].getElementsByTagName('path')[0];
if ( path ) {
var points = path.getAttribute('d').split(' ');
points[1] = 'h' + ( nodes[i].offsetWidth - 13 );
path.setAttribute( 'd', points.join(' ') );
}
}
})( document.getElementsByClassName('button') );