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>
相关推荐
IT_陈寒1 天前
Redis 性能翻倍的 5 个隐藏技巧,99% 的开发者都不知道第3点!
前端·人工智能·后端
街尾杂货店&1 天前
css word属性
前端·css
fruge1 天前
2025前端工程化与性能优化实战指南:从构建到监控的全链路方案
前端·性能优化
aesthetician1 天前
Node.js v25 重磅发布!革新与飞跃:深入探索 JavaScript 运行时的未来
javascript·node.js·vim
demi_meng1 天前
reactNative 遇到的问题记录
javascript·react native·react.js
千码君20161 天前
React Native:从react的解构看编程众多语言中的解构
java·javascript·python·react native·react.js·解包·解构
lijun_xiao20091 天前
前端最新Vue2+Vue3基础入门到实战项目全套教程
前端
90后的晨仔1 天前
Pinia 状态管理原理与实战全解析
前端·vue.js
杰克尼1 天前
JavaWeb_p165部门管理
java·开发语言·前端
EndingCoder1 天前
WebSocket实时通信:Socket.io
服务器·javascript·网络·websocket·网络协议·node.js