關(guān)于三角形的各種畫(huà)法,之前在文章《純CSS -border繪制三角形(各種角度)》內(nèi)有詳細(xì)的介紹,今天來(lái)講的是CSS繪出對(duì)話框和三角帶邊框!
真正的三角形畫(huà)法雖然重要,但常用程度甚至不如本文介紹的帶邊框三角形,因?yàn)楝F(xiàn)在網(wǎng)頁(yè)需要彈出各種信息,比如二維碼,比如聯(lián)系方式等,都需要用到對(duì)話框,這個(gè)框如果使用PS做圖的話也可行,但很浪費(fèi)時(shí)間,css直接實(shí)現(xiàn)的話更靠譜!
如上圖所示,代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>CSS 三角形對(duì)話框,三角形(帶邊框)</title> </head> <style> .find-div-body{ position: relative; top:30px; right:0px; width:400px; height:200px; padding:8px; background-color: #FFFFFF; border: #cccccc solid 1px; border-radius: 3px; } .find-div-body:before{ box-sizing: content-box; width: 0px; height: 0px; position: absolute; top: -16px;; right:41px; padding:0; border-bottom:8px solid #FFFFFF; border-top:8px solid transparent; border-left:8px solid transparent; border-right:8px solid transparent; display: block; content:''; z-index: 12; } .find-div-body:after{ box-sizing: content-box; width: 0px; height: 0px; position: absolute; top: -18px;; right:40px; padding:0; border-bottom:9px solid #cccccc; border-top:9px solid transparent; border-left:9px solid transparent; border-right:9px solid transparent; display: block; content:''; z-index:10 } </style> <body> <div class="find-div-body"> </div> </body> </html>
如上圖,主要需要用到:after和:before選擇器,這也是制作各種CSS圖形必須熟練的選擇器!