题目

答案
<!DOCTYPE html><html><head> <title></title> <meta charset="utf-8"> <style> * {margin: 0;padding: 0;} .container { width: 200px;margin: 200px auto;} .button { cursor: pointer;width: 100%;height: 50px;background: #ccc;position: relative; } .button::before {content: '';position: absolute;width: 40px;height: 40px; left: 5px; top: 5px;background: #fff;} .button:hover {animation: btn-hover-bg linear .3s forwards;} .button:hover::before {animation: btn-hover linear .3s forwards;} @keyframes btn-hover { 0% { /*transform: translateX(0);*/ left: 5px; } 100% { left: calc(100% - 45px); /*transform: translateX(50px);*/ } } @keyframes btn-hover-bg { 0% { background: #ccc; } 100% { background: green; } } </style></head><body> <div class="container"> <div class="button"></div> </div></body></html>
效果
hover效果
