使用CSS繪制基礎(chǔ)的對(duì)話框圖案的代碼示例
如下圖:左側(cè)三角形
css代碼如下:
- #talkbubble {
- margin-left:30px;
- width: 120px;
- height: 80px;
- background: red;
- position: relative;
- -moz-border-radius: 10px;
- -webkit-border-radius: 10px;
- border-radius: 10px;
- }
- #talkbubble:before {
- content:"";
- position: absolute;
- rightright: 100%;
- top: 26px;
- width: 0;
- height: 0;
- border-top: 13px solid transparent;
- border-right: 26px solid red;
- border-bottom: 13px solid transparent;
- }
其實(shí),本案例的精華就是三角形的繪制,那么如何繪制三角形呢?我在這里總結(jié)一下!
上三角形,上三角形,頂部是尖的,所以用border-left,border-right,和border-bottom可以實(shí)現(xiàn),給bottom一個(gè)顏色,其他設(shè)置為transparent
- #triangle-up {
- width: 0;
- height: 0;
- border-left: 50px solid transparent;
- border-right: 50px solid transparent;
- border-bottom: 100px solid red;
- }
同理,大家可以判斷一下如下代碼分別是什么樣的三角形!
- #triangle-down {
- width: 0;
- height: 0;
- border-left: 50px solid transparent;
- border-right: 50px solid transparent;
- border-top: 100px solid red;
- }
- #triangle-left {
- width: 0;
- height: 0;
- border-top: 50px solid transparent;
- border-right: 100px solid red;
- border-bottom: 50px solid transparent;
- }
- #triangle-rightright {
- width: 0;
- height: 0;
- border-top: 50px solid transparent;
- border-left: 100px solid red;
- border-bottom: 50px solid transparent;
- }
- #triangle-topleft {
- width: 0;
- height: 0;
- border-top: 100px solid red;
- border-right: 100px solid transparent;
- }
- #triangle-topright {
- width: 0;
- height: 0;
- border-top: 100px solid red;
- border-left: 100px solid transparent;
- }
- #triangle-bottomleft {
- width: 0;
- height: 0;
- border-bottom: 100px solid red;
- border-right: 100px solid transparent;
- }
- #triangle-bottomright {
- width: 0;
- height: 0;
- border-bottom: 100px solid red;
- border-left: 100px solid transparent;
- }
判斷出上面代碼分別代表什么三角形嗎?沒錯(cuò),我的命名是根據(jù)三角形的方向來的。大家可以試一下。三角形會(huì)寫了,那么對(duì)話框就迎刃而解了! 不管是左側(cè)的,還是上面的,只要改變一下before偽類的定位,就可以實(shí)現(xiàn)了。
當(dāng)然,三角形的寫法是很基礎(chǔ)的。你也可以用css繪制出五角星、六角星、多邊形、愛心等等。當(dāng)然有些符號(hào)是不常用的,用的最多的還是三角形。
相關(guān)文章
CSS3中設(shè)置3D變形的transform-style屬性詳解
transform-style經(jīng)常被用來做三維空間坐標(biāo)系中的圖形變換,下面我們就來看看CSS3中設(shè)置3D變形的transform-style屬性詳解,需要的朋友可以參考下2016-05-23- 下面小編就為大家?guī)硪黄猚ss 元素選擇器的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-23
- 下面小編就為大家?guī)硪黄猚ss border屬性的使用方法和技巧。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-23
- 下面小編就為大家?guī)硪黄猚ss sprite簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-23
CSS3中的Transition過度與Animation動(dòng)畫屬性使用要點(diǎn)
這篇文章主要介紹了CSS3中的Transition過度與Animation動(dòng)畫屬性使用要點(diǎn)Transition和Animation能被用來制作基本的頁(yè)面圖片動(dòng)態(tài)效果,當(dāng)然進(jìn)一步的控制還是需要JavaScript的2016-05-20- :before和:after偽元素在CSS中除了被用來添加元素、加小標(biāo)、清浮動(dòng)等,還有很多妙用之處,接下來我們就來看一兩個(gè)CSS中:before和:after偽元素使用的奇技淫巧2016-05-20
CSS凹型導(dǎo)航按鈕效果的實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄狢SS凹型導(dǎo)航按鈕效果的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧。祝大家游戲愉快哦2016-05-20
CSS3 magic帶64種動(dòng)畫庫(kù)特效源碼
magic.css是一套帶64種動(dòng)畫效果的CSS3動(dòng)畫庫(kù)。全部使用CSS3 animation動(dòng)畫來完成2016-05-19CSS文本超出指定寬度后隱藏并顯示為省略號(hào)的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狢SS文本超出指定寬度后隱藏并顯示為省略號(hào)的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-24


