вы можете включить эффект в сам градиент:
обновление кода для проверки и настройки: background: linear-gradient(90deg, transparent,dodgerblue,dodgerblue, dodgerblue, transparent) silver/* second gradient turned into bg-color*/;
Демо ниже
body {
/* pretty it up */
width: 95vw;
height: 95vh;
background-color: #666;
display: flex;
align-items: center;
justify-content: center;
}
.button {
font: 1em Arial, sans-serif;
display: inline-block;
padding: 1em;
margin: 1em;
/* border-radius: 5px; */
text-decoration: none;
color: gray;
/* Set up the hover */
/* If you aren't using autoprefix, remember to prefix the gradient for other browsers */
background: linear-gradient(90deg, transparent,dodgerblue,dodgerblue, dodgerblue, transparent) silver;
background-size: 0 5px, auto;
background-repeat: no-repeat;
background-position: center bottom;
transition: all .2s ease-out;
}
.button:hover {
/* The following line makes the underline only as wide as the text */
/* background-size: calc(100% - 2em) 5px, auto; */
background-size: 100% 5px, auto;
}
<a href="#" class="button">Checkout</a>
<a href="#" class="button">Buy now</a>
<a href="#" class="button">A really long button for absolutely no reason</a>