[转载] Html+Css实现梯形选项卡

1,先看一下效果图
在这里插入图片描述
2,梯形通过定位和设置Border来实现的,平行四边形通过旋转来实现的。

3,代码如下
1)HTML代码

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" href="Style/tab.css" type="text/css" />
    <script type="text/javascript">
        function JumpTab(url)
        {
            window.location.href = url;
        }
    </script>
</head>
<body>
    <div class="topNavigation">
         
        <div class="outDv firstOutDv currentlevel">
            <div class="innerDv currentlevel">
            </div>
            <div class="container currstart">
                合同会签申请
            </div>
 
        </div>
        <div class="outDv level4" onclick="JumpTab('second.html')">
            <div class="innerDv">
            </div>
            <div class="container next">
                合同盖章记录
            </div>
        </div>
        <div class="outDv level3" onclick="JumpTab('three.html')">
            <div class="innerDv">
            </div>
            <div class="container next">
                合同生效申请
            </div>
        </div>
        <div class="outDv level2" onclick="JumpTab('four.html')">
            <div class="innerDv">
            </div>
            <div class="container next">
                付款50%
            </div>
        </div>
        <div class="outDv level1" onclick="JumpTab('five.html')">
            <div class="innerDv">
            </div>
            <div class="container end">
                合同归档记录
            </div>
        </div>
        <div class="endDv" onclick="JumpTab('six.html')">
            <div class="innerEndDv">相似合同</div>
        </div>
        <div class="endDv" onclick="JumpTab('seven.html')">
            <div class="innerEndDv">
                相关合同
            </div>
        </div>
         
    </div>
 
</body>
</html>

(2)CSS代码

* {
    padding: 0px;
    margin: 0px;
}
 
.topNavigation {
     
    border-bottom: 5px solid #51A3C9;
    padding-right:10px;
    width:90%;
    margin:auto;
    padding-top:20px;
}
 
.firstOutDv {
    margin-left: 0px !important;
}
 
.outDv {
    border-bottom: 30px solid #b5b5b5;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    width: 125px;
    position: relative;
    margin-left: -25px;
    display: inline-block;
    margin-bottom: -4px;
    cursor: pointer;
}
 
.innerDv {
    border-bottom: 28px solid #f2f2f2;
    border-left: 19px solid transparent;
    border-right: 19px solid transparent;
    width: 123px;
    position: absolute;
    left: -18px;
    top: 1px;
     
}
 
.container {
    z-index: 10;
    position: absolute;
    padding-left: 22px;
    background-position-x: 2px;
    background-position-y: center;
    background-repeat: no-repeat;
    height: 30px;
    line-height: 30px;
}
 
.start {
    background-image: url('/Images/start.png');
}
 
.next {
    background-image: url('/Images/next.png');
}
 
.end {
    background-image: url('/Images/end.png');
}
 
.currstart {
    background-image: url('/Images/currentstart.png');
    color: #fff;
}
 
.currnext {
    background-image: url('/Images/currentnext.png');
    color: #fff;
}
 
.currend {
    background-image: url('/Images/currentend.png');
    color: #fff;
}
 
 
.level5 {
    z-index: 5;
}
 
.level4 {
    z-index: 4;
}
 
.level3 {
    z-index: 3;
}
 
.level2 {
    z-index: 2;
}
 
.level1 {
    z-index: 1;
}
 
.currentlevel {
    z-index: 6;
    border-bottom: 30px solid #51a3c9;
    top: 0px !important;
}
 
.endDv {
    width: 100px;
    height: 30px;
    transform: skew(35deg);
    -webkit-transform: skew(35deg);
    -moz-transform: skew(35deg);
    -o-transform: skew(35deg);
    -ms-transform: skew(35deg);
    background-color: #E7E7E7;
    /* margin: 50px auto; */
    display: inline-block;
    margin-bottom: -4px;
    float: right;
    text-align:center;
    margin-left:15px;
    cursor:pointer;
}
 
.innerEndDv{
    transform: skew(-35deg);
    -webkit-transform: skew(-35deg);
    -moz-transform: skew(-35deg);
    -o-transform: skew(-35deg);
    -ms-transform: skew(-35deg);
    height:30px;
    line-height:30px;
    cursor:pointer;
}
.currentEnd{
    color:#fff;
    background-color:#51A3C9;
}

来自https://www.cnblogs.com/wanren/p/7879681.html

### 使用 CSS 实现文字梯形效果 通过纯 CSS 的方式可以实现文字梯形效果而无需依赖图片资源。以下是具体方法以及代码示例: #### 方法概述 利用 `transform` 属性中的 `skew()` 函数可以使元素倾斜,从而形成梯形的效果。此外,还可以结合伪类 `::before` 和 `::after` 来创建更复杂的形状。 --- #### HTML 结构 为了保持语义化和灵活性,HTML 部分仅需简单的结构即可满足需求: ```html <div class="trapezoid-tab"> 文字梯形效果 </div> ``` --- #### CSS 样式 以下是一个完整的 CSS 示例,用于实现带有文字的梯形选项卡效果: ```css .trapezoid-tab { position: relative; display: inline-block; padding: 10px 20px; background-color: #4CAF50; /* 背景颜色 */ color: white; /* 字体颜色 */ font-size: 16px; text-align: center; } /* 左侧斜切效果 */ .trapezoid-tab::before { content: &#39;&#39;; position: absolute; top: 0; left: -20px; /* 控制左侧宽度 */ width: 20px; height: 100%; transform: skewX(30deg); /* 斜切角度 */ background-color: inherit; /* 继承父级背景色 */ z-index: -1; } /* 右侧斜切效果 */ .trapezoid-tab::after { content: &#39;&#39;; position: absolute; top: 0; right: -20px; /* 控制右侧宽度 */ width: 20px; height: 100%; transform: skewX(-30deg); /* 斜切角度 */ background-color: inherit; /* 继承父级背景色 */ z-index: -1; } ``` 上述代码实现了两侧带斜角的文字梯形效果[^1]。如果只需要单侧梯形,则可移除对应的伪元素部分。 --- #### 进阶技巧:双色拼接按钮 对于更加复杂的设计场景,比如双色拼接按钮,可以通过调整渐变或设置不同的伪元素背景来完成。例如: ```css .trapezoid-tab { background: linear-gradient(to right, #FF9800, #F44336); } ``` 此代码将使梯形区域呈现从橙色到红色的渐变过渡效果[^3]。 --- #### 边框梯形扩展 当需要为梯形添加边框时,可以借助嵌套容器或者额外的子元素实现。例如,在原有基础上增加如下样式: ```css .title .oricl span, .title .oricl1 span { border-top: 20px solid transparent; border-bottom: 20px solid transparent; border-left: 20px solid red; margin-right: -20px; float: left; } ``` 该片段展示了如何使用三角形原理构建具有边框样式的梯形组件[^2]。 --- ### 总结 以上方案提供了多种基于 CSS 的技术手段来达成文字梯形显示目标,既减少了对外部图像文件的依赖,也提升了页面加载性能。 问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值