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>
相关推荐
xw5几秒前
我犯了错,我于是为我的uni-app项目引入环境标志
前端·uni-app
!win !3 分钟前
被老板怼后,我为uni-app项目引入环境标志
前端·小程序·uni-app
Burt4 分钟前
tsdown vs tsup, 豆包回答一坨屎,还是google AI厉害
前端
群联云防护小杜1 小时前
构建分布式高防架构实现业务零中断
前端·网络·分布式·tcp/ip·安全·游戏·架构
ohMyGod_1232 小时前
React16,17,18,19新特性更新对比
前端·javascript·react.js
前端小趴菜052 小时前
React-forwardRef-useImperativeHandle
前端·vue.js·react.js
@大迁世界2 小时前
第1章 React组件开发基础
前端·javascript·react.js·前端框架·ecmascript
Hilaku2 小时前
从一个实战项目,看懂 `new DataTransfer()` 的三大妙用
前端·javascript·jquery
爱分享的程序员2 小时前
前端面试专栏-算法篇:20. 贪心算法与动态规划入门
前端·javascript·node.js
我想说一句2 小时前
事件委托与合成事件:前端性能优化的"偷懒"艺术
前端·javascript