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>
相关推荐
前端李易安1 小时前
Web常见的攻击方式及防御方法
前端
PythonFun2 小时前
Python技巧:如何避免数据输入类型错误
前端·python
hakesashou2 小时前
python交互式命令时如何清除
java·前端·python
天涯学馆2 小时前
Next.js与NextAuth:身份验证实践
前端·javascript·next.js
HEX9CF2 小时前
【CTF Web】Pikachu xss之href输出 Writeup(GET请求+反射型XSS+javascript:伪协议绕过)
开发语言·前端·javascript·安全·网络安全·ecmascript·xss
ConardLi2 小时前
Chrome:新的滚动捕捉事件助你实现更丝滑的动画效果!
前端·javascript·浏览器
ConardLi2 小时前
安全赋值运算符,新的 JavaScript 提案让你告别 trycatch !
前端·javascript
凌云行者2 小时前
使用rust写一个Web服务器——单线程版本
服务器·前端·rust
华农第一蒟蒻3 小时前
Java中JWT(JSON Web Token)的运用
java·前端·spring boot·json·token
积水成江3 小时前
关于Generator,async 和 await的介绍
前端·javascript·vue.js