如何使悬停时的按钮动画与此gif中的按钮或airforce.com中的按钮一样。

最佳答案

以下是一个包含一个元素和多个背景的想法:

.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>

10-08 05:00