css实现梯形tab切换


javascript 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <style>
        .nav{
            display: flex;
            width: 300px;
            padding: 0;
            align-items: flex-end;
            background-color: transparent
        }
        * {
            box-sizing: border-box;
        }
        .nav .item{
            flex: 1;
            height: 56px;
            background: #eee;
            position: relative;
            list-style: none;
        }
        .nav .item.active{
            background: #4F6EF7;
            z-index: 10;
        }
        .nav .item:before,.nav .item:after{
            content: '';
            width: 30px;
            height: 100%;
            position: absolute;
            background: #eee;
        }
        .nav #itemOne:before{
            right: -15px;
            transform: skew(-20deg);
        }
        .nav #itemTwo:before{
            left: -15px;
            transform: skew(-20deg);
        }
        /* .nav .item:after{
            left: -15px;
            transform: skew(-20deg);
        } */
        
        
        .nav .item.active:before,.nav .item.active:after{
            background: #4F6EF7;
            z-index: 10;
        }
        .nav .item.active:before{
            border-left: none;
        }
        .nav .item.active:after{
            border-right: none;
        }
    </style>
</head>
<body>
    <ul class="nav">
        <li id="itemOne" class="item active"></li>
        <li id="itemTwo" class="item" style="margin-left: 42px;"></li>
    </ul>
</body>
<script>
    document.querySelector('.nav').addEventListener('click',function(e){
        if(e.target.nodeName=='LI'){
            var item = document.querySelectorAll('.item');
            for(var i = 0; i < item.length; i++){
                item[i].className = 'item';
            }
            e.target.className = 'item active';
        }
    })
</script>
</html>
相关推荐
海云前端4 分钟前
前端写简历有个很大的误区,就是夸张自己做过的东西。
前端
葡萄糖o_o14 分钟前
ResizeObserver的错误
前端·javascript·html
AntBlack15 分钟前
Python : AI 太牛了 ,撸了两个 Markdown 阅读器 ,谈谈使用感受
前端·人工智能·后端
MK-mm34 分钟前
CSS盒子 flex弹性布局
前端·css·html
小小小小宇1 小时前
CSP的使用
前端
sunbyte1 小时前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | AnimatedNavigation(动态导航)
前端·javascript·vue.js·tailwindcss
ifanatic1 小时前
[每周一更]-(第147期):使用 Go 语言实现 JSON Web Token (JWT)
前端·golang·json
烛阴1 小时前
深入浅出地理解Python元类【从入门到精通】
前端·python
米粒宝的爸爸1 小时前
uniapp中vue3 ,uview-plus使用!
前端·vue.js·uni-app
JustHappy1 小时前
啥是Hooks?为啥要用Hooks?Hooks该怎么用?像是Vue中的什么?React Hooks的使用姿势(下)
前端·javascript·react.js