正向动画:可以不断追加 background-size x 轴的大小来控制,当鼠标移入的时候,不断追加 background-size X轴大小
反向动画:可以在 鼠标移出的时候,吧 background-position 的 x 轴 设置成 right ,先从右边体现
3、代码
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Document</title><style>.underline{line-height: 2;background:linear-gradient(to right, red, red);background-size: 0 2px;background-repeat: no-repeat;background-position: right bottom;transition: background-size 0.8s;}div span:hover{background-position: left bottom;background-size: 100% 2px;}</style></head><body><div><spanclass="underline">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem alias accusamus maxime exercitationem fugitrepudiandae a quaerat in sint aliquid officiis, minima, illo, molestias repellendus sequi? Dolores quisquamarchitectoaliquam.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem alias accusamus maxime exercitationemfugitrepudiandae a quaerat in sint aliquid officiis, minima, illo, molestias repellendus sequi? Dolores quisquamarchitectoaliquam.Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem alias accusamus maxime exercitationemfugitrepudiandae a quaerat in sint aliquid officiis, minima, illo, molestias repellendus sequi? Dolores quisquamarchitectoaliquam.</span></div></body></html>