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>
相关推荐
zhengfei6118 分钟前
【XSS payload 】一个经典的XSS payload
前端·xss
简单Janeee19 分钟前
[Vue 3 从零到上线]-第四篇:组件化思维——把网页像积木一样拆解
javascript·vue.js·ecmascript
全栈老石1 小时前
手写一个无限画布 #1:坐标系的谎言
前端·canvas
XW01059992 小时前
4-11判断素数
前端·python·算法·素数
J2虾虾2 小时前
Spring Boot中使用@Scheduled做定时任务
java·前端·spring boot
Heo2 小时前
深入React19任务调度器Scheduler
前端·javascript·面试
一枚前端小姐姐2 小时前
Vue3 + Pinia 状态管理,从入门到模块化
前端·vue.js
boooooooom2 小时前
Vue3 nextTick 实现大变化:微任务优先,彻底搞懂渲染时机!
javascript·vue.js·面试
用户14436183400972 小时前
你不知道的JS上-(九)
前端·javascript
yuki_uix2 小时前
为什么我的 Auth Token 藏在了 Network 面板的 Doc 里?
前端·python·debug