轉:http://blog.csdn.net/tangtang5963/article/details/51490107
https://segmentfault.com/a/1190000002780453#articleHeader18
css實現各種圖形真是太贊了,再也不用切圖了,直接用css就可以實現。
最常用的就是用css實現的小三角了
#triangle-up{ display:inline-block; width:0; height:0; border-left:30px solid transparent; border-right: 30px solid transparent; border-bottom:50px solid red;} #triangle-down { display:inline-block; width:0; height:0; border-left:30px solid transparent; border-right: 30px solid transparent; border-top:50px solid red;} #triangle-left { display:inline-block; width:0; height:0; border-top: 30px solid transparent; border-right: 50px solid red; border-bottom: 30px solid transparent;} #triangle-right{ display:inline-block; width:0; height:0; border-top: 30px solid transparent; border-left: 50px solid red; border-bottom: 30px solid transparent;}
#triangle-topleft { display:inline-block; width: 0; height: 0; border-top: 50px solid red; border-right: 50px solid transparent; } #triangle-topright { display:inline-block; width: 0; height: 0; border-top: 50px solid red; border-left: 50px solid transparent; } #triangle-bottomleft { display:inline-block; width: 0; height: 0; border-bottom: 50px solid red; border-right: 50px solid transparent; } #triangle-bottomright { display:inline-block; width: 0; height: 0; border-bottom: 50px solid red; border-left: 50px solid transparent; }
通過這樣的小箭頭在項目中我們可以實現驗證提示層箭頭這樣的樣式,非常的實用,再也不用為提示層樣式發愁啦。
我們看到了實現css小箭頭的style樣式中都用到了transparent這樣的一個屬性,transparent到底是什么意思?於是查看了css參考手冊,定義是:
用來指定全透明色彩。
- transparent是全透明黑色(black)的速記法,即一個類似rgba(0,0,0,0)這樣的值。
- 在CSS1中,transparent被用來作為background-color的一個參數值,用於表示背景透明。
- 在CSS2中,border-color也開始接受transparent作為參數值。
- 在CSS3中,transparent被延伸到任何一個有color值的屬性上。
transparent我總結意思就是透明,無顏色的。
看圖,三角形的實現實際上是一個寬度和高度都為0的div的四個邊框實現的,如果我們要實現朝下的箭頭,那就要讓div的左~右 邊框都為透明(透明但左右邊框還占位置)。
左上箭頭 實現思路是什么呢?div的右邊框和底部邊框都為透明,這樣左上角的箭頭就露出來了。
css3實現心形