css实现带边框的三角形

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<style type="text/css"> 
		.tab-container{
			width:252px;
		}
		.tab{
			position:relative;
			height:40px;
			float:left;
			width:250px;
			margin-top:10px;
			border:1px solid #5ec264;
			cursor:pointer;
		}
		.tab-left{
			height:40px;
			line-height:40px;
			float:left;
			width:50px;
			background-color:#fff;
			text-align:center;
		}
		.tab-left:after{
			width:0;
			height:0;
			content:'';
			position:absolute; 
			border-width:20px 0 20px 16px;
			border-style:solid;
			border-color:transparent transparent transparent #fff;
			top: 0;
			left: 50px;
		}
		.tab-left:before{
			width:0;
			height:0;
			content:'';
			position:absolute; 
			border-width:20px 0 20px 16px;
			border-style:solid;
			border-color:transparent transparent transparent #5ec264;
			top: 0;
			left: 52px;
		}
		.tab-right{
			height:40px;
			line-height:40px;
			width:200px;
			float:left;
			background-color:#fff;
			text-align:center;
		}
		.tab.selected .tab-left{
			background-color:#5ec264;
		}
		.tab.selected .tab-left:before{
			border-color:transparent transparent transparent #fff;
		}
		.tab.selected .tab-left:after{
			border-color:transparent transparent transparent #5ec264;
		}
		.tab.selected .tab-right{
			background-color:#5ec264;
		}
		.tab a{
			font-size:15px;
			color:#5ec264;
		}
		.tab.selected a{
			color:#fff;
		}
	</style>
</head>
	<body>
		<div class="tab-container">
		    <p>带边框三角形的实现,大小两个三角形重叠,较大的位于下方作为边框,较小的浮于上方作为三角形的内容</p>
			<div class="tab">
				<div class="tab-left"><a>1</a></div>
				<div class="tab-right"><a>222 sgsd</a></div>
			</div>
			<div class="tab selected">
				<div class="tab-left"><a>2</a></div>
				<div class="tab-right"><a>222 sgsd</a></div>
			</div>
			<p>使用元素的before和after属性,优先级after高于before,然后分别做出两个形状大小相同的小三角形,before的border-color是元素的边框颜色,after的border-color是元素的背景颜色,然后错开重叠,就能形成边框的效果。</p>
		</div>
	</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值