Css if the navigation bar switch, underline caterpillar switch effect?

found a similar effect on the Internet:
,
switching effect and caterpillar switching effect (the width of the underscore
from tab1 to tab2,tab1 is gradually shorter, and the width of the underscore of tab2 is gradually longer). There is no idea for the time being.

Mar.03,2022

the biggest feature of the caterpillar effect is its silky fluency, that is, it is always "a caterpillar" running under the label. I have read this article before, but it is not slippery. Then I came up with an idea, but it felt too out of the mainstream. And the complete effect can only be written in sass or less.
for example: there are now 5 tags, and I precisely control the length of each li tag. Then I just need to set the pseudo element after, under the first tag as a "caterpillar". When I mouse over the second tab, I use transform to move the position of the after so that it is just below the second tab. This method is still very troublesome, and the problem of positioning may be taken into account. At the same time, it seems that the back and forth direction cannot be controlled, and each tag hover must be judged.

Menu