使用CSS繪制基礎(chǔ)的對話框圖案的代碼示例
Haorooms 發(fā)布時間:2016-05-20 12:00:23 作者:Aaron
我要評論

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