CSS3 导航栏下划线跟随效果

2019-04-14  本文已影响0人  Gino_Li
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>

        </title>
        <style>
            ul {
                display: flex;
                position: absolute;
                width: 800px;
                top: 30%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
            
            li {
                position: relative;
                padding: 20px;
                font-size: 24px;
                color: #000;
                line-height: 1;
                transition: 1s all linear;
                cursor: pointer;
                list-style: none;
            }
            
            li::before {
                content: "";
                position: absolute;
                top: 0;
                left: 100%;
                width: 0;
                height: 100%;
                border-bottom: 2px solid #000;
                transition: 0.2s all linear;
            }
            
            li:hover::before {
                width: 100%;
                top: 0;
                left: 0;
                z-index: -1;
                transition-delay: 0.1s;
            }
            
            li:hover~li::before {
                left: 0;//关键,hover的时候其他兄弟元素li变0
            }
        </style>
    </head>

    <body>
        <ul>
            <li>首页</li>
            <li>新闻</li>
            <li>个人中心</li>
            <li>关于我们</li>
            <li>联系我们</li>
        </ul>
    </body>
</html>
上一篇下一篇

猜你喜欢

热点阅读