html代码
<a href="https://wdja.cn">
<button>
查看详情<span>→</span>
</button>
</a>
css代码
a {
display: block;
padding: 8% 0 10%;
}
a button {
overflow: hidden;
position: relative;
display: inline-block;
width: 130px;
padding: 18px 15px;
border: 1px solid #1c2020;
border-radius: 4px;
font-size: 12px;
line-height: 0;
z-index: 1;
background: none;
text-align: left;
font-family: 'MS PGothic', arial, helvetica, sans-serif;
cursor: pointer;
}
a:hover button::before {
width: 110%;
transition: all 0.2s ease-in-out;
z-index: -1;
}
a button::before {
background: #1c2020;
content: "";
position: absolute;
left: -10px;
top: 0px;
height: 100%;
width: 0;
transition: all 0.2s ease-in-out;
z-index: -1;
}
通过设置原始宽度为0,鼠标覆盖时,设置宽度100.同时设置动画时间.实现