亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

div+CSS制作類似微信對話氣泡效果的實(shí)例總結(jié)

cnblogs   發(fā)布時(shí)間:2016-04-01 11:10:14   作者:Stoneniqiu   我要評論
這篇文章主要介紹了div+CSS制作類似微信對話氣泡效果的實(shí)例總結(jié),文中總結(jié)出了四種編寫方式,并且對三角形的繪制有一個(gè)補(bǔ)充說明,需要的朋友可以參考下

在聊天的場景中,聊天內(nèi)容需要用到氣泡修飾,如下圖。下面一一講解。
201641111629651.png (648×466)

一、圖片式:

第一個(gè)樣式是京東客服,氣泡的圓角和鉤子都是用了圖片。使用了一個(gè)table組合成了一個(gè)圓角的框框。lm樣式拼出了鉤子。

 

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div class="jimi_lists clearfix">  
  2.                 <div class="header_img jimi3 fl"></div>  
  3.                 <table class="msg" cellspacing="0" cellpadding="0">  
  4.                     <tbody><tr><td class="lt"></td><td class="tt"></td><td class="rt"></td></tr>  
  5.                     <tr><td class="lm"><span></span></td><td class="mm"><span class="wel"><span class="visitor"><p>很抱歉,現(xiàn)在人工客服忙,讓小JIMI為您解答吧。</p></span></span></td><td class="rm"></td></tr>  
  6.                     <tr><td class="lb"></td><td class="bm"></td><td class="rb"></td></tr><tr><td></td></tr>  
  7.                     </tbody>  
  8.                 </table>  
  9.             </div>  
  10.             <div class="customer_lists clearfix">  
  11.                 <div class="header_img jimi3" style="background: url(img/mine.jpg) no-repeat center;">  
  12.                     <div class="header_img_hover"></div>  
  13.                 </div>  
  14.                 <table class="msg" cellspacing="0" cellpadding="0"><tbody><tr><td class="lt"></td><td class="tt"></td><td class="rt"></td></tr><tr><td class="lm"></td><td class="mm">你好,我是stoneniqiu</td><td class="rm"><span></span></td></tr><tr><td class="lb"></td><td class="bm"></td><td class="rb"></td></tr><tr><td></td><td class="time"></td><td></td></tr></tbody></table>  
  15.             </div>  

樣式:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .jimi_lists {   
  2.     margin: 0 -10px 20px 10px;   
  3.     positionrelative;   
  4. }   
  5.  .jimi_lists .header_img.jimi3 {   
  6.     backgroundurl(../img/jimi_50_3.png) no-repeat 0 0;   
  7. }   
  8.  .jimi_lists .header_img {   
  9.     width50px;   
  10.     height50px;   
  11.     positionabsolute;   
  12.     top: 0;   
  13.     left: 0;   
  14. }   
  15. .fl {   
  16.     floatleft;   
  17. }   
  18.  .jimi_lists .msg {   
  19.     margin-left59px;   
  20.     margin-right40px;   
  21.     margin-top2px;   
  22.     floatleft;   
  23.     displayinline;   
  24. }   
  25.  .jimi_lists .lt {   
  26.     backgroundurl(../img/msg_bg_lr.png) no-repeat 0 0;   
  27.     width26px;   
  28.     height10px;   
  29. }   
  30.  .jimi_lists .tt {   
  31.     backgroundurl(../img/msg_bg_tb.png) repeat-x 0 -23px;   
  32.     height10px;   
  33. }   
  34. .jimi_lists .rt {   
  35.     backgroundurl(../img/msg_bg_lr.png) no-repeat -35px 0;   
  36.     width10px;   
  37.     height10px;   
  38. }   
  39. .jimi_lists .lm {   
  40.     backgroundurl(../img/msg_bg_lr.png) repeat-y -94px 0;   
  41.     width26px;   
  42.     vertical-aligntop;   
  43.     positionrelative;   
  44. }   
  45. .jimi_lists .mm {   
  46.     padding: 0 5px;   
  47.     background-color#FFF;   
  48.     word-break: break-all;   
  49.     word-wrap: break-word;   
  50.     color#333;   
  51.     line-height20px;   
  52. }   
  53. .jimi_lists .lm span {   
  54.     backgroundurl(../img/msg_bg_lr.png) no-repeat 0 -14px;   
  55.     displayinline-block;   
  56.     width26px;   
  57.     height16px;   
  58.     positionabsolute;   
  59.     top5px;   
  60. }   
  61. .jimi_lists .rm {   
  62.     backgroundurl(../img/msg_bg_lr.png) repeat-y -113px 0;   
  63.     width10px;   
  64. }   
  65. .jimi_lists .lb {   
  66.     backgroundurl(../img/msg_bg_lr.png) no-repeat 0 -43px;   
  67.     width10px;   
  68.     height10px;   
  69. }   
  70. .jimi_lists .bm {   
  71.     backgroundurl(../img/msg_bg_tb.png) repeat-x 0 -25px;   
  72.     height10px;   
  73. }   
  74. .jimi_lists .rb {   
  75.     backgroundurl(../img/msg_bg_lr.png) no-repeat -35px -43px;   
  76.     width10px;   
  77.     height10px;   
  78. }   
  79.   
  80. .customer_lists {   
  81.     positionrelative;   
  82.     margin: 0 12px 20px 20px;   
  83. }   
  84. .customer_lists .msg {   
  85.     floatrightright;   
  86.     margin-right73px;   
  87.     _margin-rightright38px;   
  88.     margin-top2px;   
  89. }   
  90. .customer_lists .lt {   
  91.     backgroundurl(../img/msg_bg_lr.png) no-repeat -47px -0;   
  92.     width10px;   
  93.     height10px;   
  94. }   
  95. .customer_lists .tt {   
  96.     backgroundurl(../img/msg_bg_tb.png) repeat-x 0 0;   
  97.     height10px;   
  98. }   
  99. .customer_lists .rt {   
  100.     backgroundurl(../img/msg_bg_lr.png) no-repeat -63px 0;   
  101.     width26px;   
  102.     height10px;   
  103. }   
  104. .customer_lists .lm {   
  105.     backgroundurl(../img/msg_bg_lr.png) repeat-y -126px 0;   
  106.     width10px;   
  107. }   
  108. .customer_lists .mm {   
  109.     padding1px 8px;   
  110.     background-color#3897E7;   
  111.     word-break: break-all;   
  112.     word-wrap: break-word;   
  113.     color#FFF;   
  114. }   
  115. .customer_lists .rm {   
  116.     backgroundurl(../img/msg_bg_lr.png) repeat-y -129px 0;   
  117.     width26px;   
  118.     vertical-aligntop;   
  119.     positionrelative;   
  120. }   
  121. .customer_lists .lb {   
  122.     backgroundurl(../img/msg_bg_lr.png) no-repeat -47px -36px;   
  123.     width10px;   
  124.     height10px;   
  125. }   
  126. .customer_lists .bm {   
  127.     backgroundurl(../img/msg_bg_tb.png) repeat-x -106px -4px;   
  128.     height10px;   
  129. }   
  130. .customer_lists .rb {   
  131.     backgroundurl(../img/msg_bg_lr.png) no-repeat -63px -36px;   
  132.     width26px;   
  133.     height10px;   
  134. }   
  135.   
  136. .customer_lists .rm span {   
  137.     backgroundurl(../img/msg_bg_lr.png) no-repeat -63px -14px;   
  138.     displayinline-block;   
  139.     width26px;   
  140.     height16px;   
  141.     positionabsolute;   
  142.     top5px;   
  143. }   
  144.   
  145. .customer_lists .header_img_hover {   
  146.     positionabsolute;   
  147.     backgroundurl(../img/avatar_mask_01.png);   
  148.     top: 0;   
  149.     width50px;   
  150.     height50px;   
  151. }   
  152. .customer_lists .header_img {   
  153.     positionabsolute;   
  154.     top: 0;   
  155.     rightright14px;   
  156.     width50px;   
  157.     height50px;   
  158. }   
  159.  .clearfix:after {   
  160.     content" .";   
  161.     displayblock;   
  162.     clearboth;   
  163.     visibilityhidden;   
  164.     height: 0;   
  165. }  

二、背景式:

第二種主要是使用了:before偽類畫出了三角形,然后用定位拼在了一起。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div class="jimi_lists clearfix">  
  2.                 <div class="header_img jimi3 fl"></div>  
  3.                 <div class="bkbubble right">  
  4.                      <p>換個(gè)氣泡如何</p>  
  5.                 </div>  
  6.             </div>  
  7.             <div class="customer_lists clearfix">  
  8.                 <div class="header_img jimi3" style="background: url(img/mine.jpg) no-repeat center;">  
  9.                     <div class="header_img_hover"></div>  
  10.                 </div>  
  11.                 <div class="bkbubble left">  
  12.                     <p>這個(gè)不錯</p>  
  13.                 </div>  
  14.             </div>  

(至于畫三角形的方法稍后文章最后會總結(jié)一下)
樣式:           

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .bkbubble.rightright p:before, .bkbubble.left p:before {   
  2.       width: 0;   
  3.     positionabsolute;   
  4.     top12px;   
  5.     border-stylesolid;   
  6.     content"";   
  7.   }   
  8.   .bkbubble.left {   
  9.       text-alignrightright;   
  10.   }   
  11.  .bkbubble.rightright p:before {   
  12.      left: -12px;   
  13.     border-colortransparent #00bfff;   
  14.     border-width: 0 12px 12px 0;   
  15.  }   
  16.  .bkbubble.left p:before {   
  17.      rightright: -12px;   
  18.     border-colortransparent #00bfff;   
  19.     border-width: 0 0 12px 12px ;   
  20.  }             

          
三、邊框式:

如果要求邊框顏色和背景顏色不一樣呢?上面的方法就不行了,因?yàn)橛?before畫三角形是利用border的原理,也就是說,在上面這種方式下,氣泡邊上的小三形是無法呈現(xiàn)兩種顏色的,因?yàn)樗挥幸粋€(gè)border的顏色。那就要想辦法湊出一個(gè)有邊框的三角形了。

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <div class="jimi_lists lim_operator clearfix">  
  2.                 <div class="header_img jimi3 fl"></div>  
  3.                 <div class="lim_bubble lim_shadow"><p class="lim_dot">您好,請問有什么可以幫到您?</p></div>  
  4.                 <div class="lim_tale"><div class="radiusborder"></div></div>  
  5.             </div>  

1.先畫一個(gè)小矩形。

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .lim_operator .lim_tale {   
  2.     left: -1px;   
  3.     background-color#c8f064;   
  4.     border-color#a5d01b;   
  5.     margin-left70px;   
  6. }   
  7. .lim_tale {   
  8.     positionabsolute;   
  9.     width12px;   
  10.     height8px;   
  11.     overflowhidden !important;   
  12.     top10px;   
  13.     z-index: 2;   
  14.     border-top-style: solid;   
  15.     border-top-width1px;   
  16. }  

201641111707634.png (349×82)

2.畫出斜線。

css里面是沒有斜線的,這里是用了一個(gè)園的弧形拼出來的。在一個(gè)大圓上,截取一段弧,就是一條斜線了。

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .lim_operator .radiusborder {   
  2.     positionabsolute;   
  3.     background-color#EFF0F2;   
  4.     top: -29px;   
  5.     left: -94px;   
  6.     height160px;   
  7.     width160px;   
  8.     border-top-style: solid;   
  9.     border-top-width1px;   
  10.     border-right-style: solid;   
  11.     border-right-width1px;   
  12.     border-top-rightright-radius: 154px;   
  13.     border-color#a5d01b;   
  14. }  

四、疊加式:

原理就是相當(dāng)于用before先畫出一個(gè)有色背景,再用after畫出一個(gè)白色背景,然后疊加錯開頂部1-2px,這樣就出現(xiàn)了一個(gè)有邊框有背景的三角形。web 微信就是這種做法

CSS Code復(fù)制內(nèi)容到剪貼板
  1. .expression:before {   
  2.     content'';   
  3.     positionabsolute;   
  4.     left16px;   
  5.     top: 100%;   
  6.     margin-left: -7px;   
  7.     border7px solid transparent;   
  8.     border-top-color#CFCFCF  
  9. }   
  10.   
  11. .expression:after {   
  12.     content'';   
  13.     positionabsolute;   
  14.     left16px;   
  15.     top: 100%;   
  16.     margin-left: -7px;   
  17.     margin-top: -1px;   
  18.     border7px solid transparent;   
  19.     border-top-color#FFF  
  20. }  

PS:三角形的簡單繪制:
1.CSS 邊框
201641111800289.png (600×200)

這也是一個(gè)常用的使用方式,如tooltips信息提示框和下拉菜單。以上的示例,這是一個(gè)我最喜歡的方法創(chuàng)建小而且有用的三角形。

優(yōu)點(diǎn):

很容易的通過修改一些CSS代碼屬性值而更改顏色和大小
這是一個(gè)跨瀏覽器的解決方案。
缺點(diǎn):

這個(gè)方式使用的是border,所以你不能添加陰影、漸變、和其他一些CSS3效果
請記住,IE6是不支持透明邊界的-如果你關(guān)心這個(gè)問題
2.HTML 字符
201641111819677.png (600×200)

它是基于使用可用的Unicode字符列表的字符。

優(yōu)點(diǎn)

它是一個(gè)跨瀏覽器的技術(shù)
您可以使用CSS3的text-shadow屬性添加陰影。
缺點(diǎn)

不能使用太多的CSS3效果,除了使用文字陰影。
在所有的瀏覽器,這是相當(dāng)不可能實(shí)現(xiàn)像素完美。
3.CSS 旋轉(zhuǎn)正方形
201641111841502.png (600×200)

理論上,這種方式,你需要使用兩個(gè)內(nèi)容塊,但是,并沒有限制是使用兩個(gè)元素,所以可以使用一個(gè)元素加一個(gè)偽元素。

創(chuàng)建一個(gè)內(nèi)容里。例如100×100像素 – 這將包含旋轉(zhuǎn)塊。
旋轉(zhuǎn)包含的這個(gè)塊45度,從而獲得一個(gè)菱形
將菱形的塊向頂部便宜,然后設(shè)置溢出,設(shè)置父層容器截?cái)?br />There you go!
優(yōu)點(diǎn):

CSS3陰影,漸變等可以更多的使用
缺點(diǎn):

這個(gè)解決方案不是跨瀏覽器的,首先是因?yàn)镃SS3旋轉(zhuǎn)。        

相關(guān)文章

最新評論