复制代码代码如下: .effect { position: absolute; left: -12.5%; transition: 0.7s ease-in-out; } .nav a:nth-child(1):hover ~ .effect { left: 12.5%; /* the middle of the first <a> */} .nav a:nth-child(2):hover ~ .effect { left: 37.5%; /* the middle of the second <a> */ } .nav a:nth-child(3):hover ~ .effect { left: 62.5%; /* the middle of the third <a> */} .nav a:nth-child(4):hover ~ .effect { left: 87.5%; /* the middle of the forth <a> */}