话不多说先附上代码

  <style>


        ul li {
            float: left;
            display: block;
            list-style: none;
            margin-left: 20px;
            border-bottom: 2px black solid;
            position: relative;
        }
        ul li::before {
            content: "";
            position: absolute;
            top: 0;
            left: 100%;
            width: 0;
            height: 100%;
            border-bottom: 2px solid #000;
            transition: 0.2s all linear;
        }

        ul li:hover::before {
            width: 100%;
            left: 0;
        }

        ul li:hover~li::before {
            left: 0;
        }
    </style>
</head>

<body>
    <ul>
        <li>跟着</li>
        <li>导航栏</li>
        <li>光标小下划线跟随</li>
        <li>跟随走动的下划线</li>
        <li>跟随走动</li>
    </ul>
</body>

通配符~的作用是当前元素的下一个元素

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2021-09-19
  • 2021-09-19
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-09-19
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
相关资源
相似解决方案