您好,登錄后才能下訂單哦!
本篇文章展示了css3實現(xiàn)三角形的具體操作,代碼簡明扼要容易理解,絕對能讓你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
css3三角形使用場景
我們知道有一個特效是span下拉列表,也就是說當鼠標放上一個div時,會出現(xiàn)原本隱藏的內(nèi)容或者二級菜單,這樣一個下拉列表會突出來一個小的三角形指向原本的div區(qū)域塊,如圖所示:
那么我們現(xiàn)在來總結(jié)一下,我們是如何寫出這些三角形的。
CSS3三角形實現(xiàn)原理
在css3中,我們主要使用的是一個transparent的屬性,意思是透明的,比如我們將字體設(shè)置為黑色會寫color:black,那么如果想把字體的顏色設(shè)置為透明,我們可以寫color:transparent。同理background-color:transparent可以設(shè)置背景為透明。
三角形8種分類
我們根據(jù)三角形的位置分為8種:
triangle up,triangle down,triangle left,triangle right,triangle top left,triangle top right,triangle bottom left和triangle bottom right。
8種三角形實現(xiàn)實例
1.triangle up 上三角形
#triangle-up{ width:0; height:0; border-left:50px solid transparent; border-right:50px solid transparent; border-bottom:100px solid black; }
2.triangle down 下三角形
#triangle-down{ width:0; height:0; border-left:50px solid transparent; border-right:50px solid transparent; border-top:100px solid black; }
3.triangle left 左三角形
#triangle-left{ width:0; height:0; border-top:50px solid transparent; border-bottom:50px solid transparent; border-right:100px solid black; }
4.triangle right 右三角形
#triangle-right{ width:0; height:0; border-top:50px solid transparent; border-bottom:50px solid transparent; border-left:100px solid black; }
5.triangle top left 左上三角形
#triangle-topleft{ width:0; height:0; border-top:100px solid black; border-right:100px solid transparent; }
6.triangle top right 右上三角形
#triangle-topright{ width:0; height:0; border-top:100px solid black; border-left:100px solid transparent; }
7.triangle bottom left 左下三角形
#triangle-bottomleft{ width:0; height:0; border-bottom:100px solid black; border-right:100px solid transparent; }
8.triangle bottom right 右下三角形
#triangle-bottomright{ width:0; height:0; border-bottom:100px solid black; border-left:100px solid transparent; }
大致的效果如圖所示:
看完上述內(nèi)容,你們掌握css3實現(xiàn)三角形的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。