Вот идея с одним элементом и несколькими фонами:
.box {
display:inline-block;
padding:10px 20px;
border-right:1px solid;
border-left:1px solid;
background:
linear-gradient(#000,#000) top left,
linear-gradient(#000,#000) top right,
linear-gradient(#000,#000) bottom right,
linear-gradient(#000,#000) bottom left;
background-size:15% 1px,75% 1px;
background-repeat:no-repeat;
transition:.8s all;
}
.box:hover {
background-size:75% 1px,15% 1px;
}
<div class="box">
some text
</div>
<div class="box">
more and more text
</div>
Если вы хотите исправить пробелы, вы можете настроить background-size
.Вот пример с 10px
для прозрачной части, начинающейся с 10px
от края.
.box {
display:inline-block;
padding:10px 20px;
border-right:1px solid;
border-left:1px solid;
background:
linear-gradient(#000,#000) top left,
linear-gradient(#000,#000) top right,
linear-gradient(#000,#000) bottom right,
linear-gradient(#000,#000) bottom left;
background-size:10px 1px,calc(100% - 20px) 1px;
background-repeat:no-repeat;
transition:.8s all;
}
.box:hover {
background-size:calc(100% - 20px) 1px,10px 1px;
}
<div class="box">
some text
</div>
<div class="box">
more and more text
</div>
Еще одна идея с градиентом:
.box {
display:inline-block;
padding:10px 20px;
border-right:1px solid;
border-left:1px solid;
background:
linear-gradient(to right,
#000 calc(50% - 5px),transparent calc(50% - 5px),
transparent calc(50% + 5px),#000 calc(50% + 5px)),
linear-gradient(to right,
#000 calc(50% - 5px),transparent calc(50% - 5px),
transparent calc(50% + 5px),#000 calc(50% + 5px));
background-size:150% 1px;
background-position:top left,bottom right;
background-repeat:no-repeat;
transition:.8s all;
}
.box:hover {
background-position:top right,bottom left;
}
<div class="box">
some text
</div>
<div class="box">
more and more text
</div>