[英]CSS Trapezoid Button With Solid Border
.trapezoid { width: 230px; text-align: center; height: 0; position: relative; border-right: 50px solid transparent; border-top: 40px solid #2963BD; border-left: 50px solid transparent; box-sizing: content-box; } .trapezoid span { position: absolute; top: -30px; left: 25%; color: #fff; }
<div class="trapezoid"><span>Trapezoid Button</span></div>
嘗試以下代碼:
選項1:純CSS
這種方法的邏輯是在底部添加一個粗邊框,在右側添加一個透明透明邊框,以實現Tab效果。
.tabs { display: flex; flex-direction: row; } .tab { height: 0; width: 120px; border-bottom: 50px solid #CCCCCC; border-right: 20px solid transparent; border-top-left-radius: 5px; box-sizing: border-box; display: block; } .tab:not(:first-child) { margin-left: -10px; z-index: 0; } .tab .label{ padding: 15px; text-align: center; color: #444444; } .active { border-bottom: 50px solid #444444; z-index: 10; } .active .label{ color: #ffffff; }
<div class="tabs"> <div class="tab active"><div class="label">TAB 1</div></div> <div class="tab"><div class="label">TAB 2</div></div> <div class="tab"><div class="label">TAB 3</div></div> </div>
選項2:使用SVG作為標簽背景
這種方法的邏輯是使用兩個單獨的矢量圖像(svg)作為嵌入式背景圖像:
.tabs { display: flex; flex-direction: row; overflow: visible; padding-left: 15px; } .tab { height: 0; width: 130px; height: 38px; margin-left: -15px; z-index: -1; cursor: pointer; background-size: contain; background: transparent url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width=\\"121px\\" height=\\"38px\\" viewBox=\\"0 0 121 38\\"><path d=\\"M0.786477689,37.3880765 L0.786477689,5 L0.786477689,5 C0.786477689,2.790861 2.57733869,1 4.78647769,1 L102.838012,1 L102.838012,1 C104.471746,1 105.941285,1.99354246 106.549997,3.50964209 L120.152151,37.3880765 L0.786477689,37.3880765 Z\\" stroke=\\"#979797\\" fill=\\"#F0F0F0\\"></path></svg>") no-repeat; } .tab .label{ box-sizing: border-box; padding: 12px; text-align: center; color: #444444; font: 13px arial, sans-serif; width: 90%; } .active { background: transparent url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width=\\"121px\\" height=\\"38px\\" viewBox=\\"0 0 121 38\\"><path d=\\"M0.786477689,37.3880765 L0.786477689,5 L0.786477689,5 C0.786477689,2.790861 2.57733869,1 4.78647769,1 L102.838012,1 L102.838012,1 C104.471746,1 105.941285,1.99354246 106.549997,3.50964209 L120.152151,37.3880765 L0.786477689,37.3880765 Z\\" stroke=\\"#2D94B5\\" fill=\\"#2D94B5\\"></path></svg>") no-repeat; z-index: 10; } .active .label{ color: #ffffff; }
<div class="tabs"> <div class="tab"><div class="label">TAB 1</div></div> <div class="tab"><div class="label">TAB 2</div></div> <div class="tab active"><div class="label">TAB 3</div></div> <div class="tab"><div class="label">TAB 4</div></div> </div>
如果要更改背景(填充)和邊框(描邊)的顏色,只需分析.tab
和.active
類,查找background
屬性,然后在嵌入式svg上搜索/編輯以下內容:
stroke=\\"#979797\\" fill=\\"#F0F0F0\\"
stroke=\\"#2D94B5\\" fill=\\"#2D94B5\\"
希望對您有幫助
.tabButton{ background: #ff0000; width: 100px; padding: 5px; position: relative; } .tabButton:before{ content: ' '; position: absolute; top: 8px; right: -20px; border: 20px solid transparent; border-top-color: #ff0000; transform: rotate(45deg) }
<div class="tabButton"> Navigator </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.