濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > HTML5實(shí)現(xiàn)QQ聊天氣泡效果

HTML5實(shí)現(xiàn)QQ聊天氣泡效果

熱門標(biāo)簽:農(nóng)村住宅地圖標(biāo)注 威海營(yíng)銷外呼系統(tǒng)招商 漳州人工外呼系統(tǒng)排名 跟電銷機(jī)器人做同事 ai電銷機(jī)器人連接網(wǎng)關(guān) 濟(jì)南辦理400電話 鄭州電銷外呼系統(tǒng)違法嗎 鶴壁手機(jī)自動(dòng)外呼系統(tǒng)怎么安裝 中紳電銷智能機(jī)器人

今天自己用 HTML/CSS 做了個(gè)類似QQ的聊天氣泡,以下是效果圖:

以下說下關(guān)鍵地方的樣式設(shè)置。然后貼出html和css代碼(不多)。

步驟1:布局
 

消息採用div+float布局,每條消息用一個(gè)DIV標(biāo)簽包裹,里面再放兩個(gè)DIV分別用來包裹用戶圖標(biāo)和用戶消息內(nèi)容。左側(cè)消息,先清除浮動(dòng),然后設(shè)置 float:left。這樣用戶圖標(biāo)和消息內(nèi)容就能夠顯示在同一行了,當(dāng)中用戶圖標(biāo)在左邊,消息內(nèi)容緊鄰著用戶圖標(biāo)。

右側(cè)消息,相同先清除浮動(dòng)。然后設(shè)置 float:right,這樣用戶圖標(biāo)和消息顯示在同一行了。當(dāng)中圖標(biāo)在最右邊。圖標(biāo)左側(cè)是消息。

步驟2:設(shè)置圓角矩形

border-radius:7px;     

步驟3:三角形箭頭
&n

將DIV的寬度和高度設(shè)置為0,設(shè)置邊框?qū)挾龋軌蚴蛊浔憩F(xiàn)出一個(gè)由四個(gè)三角形組成的矩形,每一個(gè)三角形的顏色和大小能夠通過設(shè)置border寬度和顏色設(shè)置。

這里將當(dāng)中三個(gè)三角形顏色設(shè)置為透明。僅僅留下一個(gè)三角形可見。

    .triangle{
        width: 0px;
        height: 0px;
        border-width: 15px;
        border-style: solid;
        border-color: red blue green gold;
    }

  .triangle{
        width: 0px;
        height: 0px;
        border-width: 15px;
        border-style: solid;
        border-color: transparent transparent transparent red;
    }

關(guān)鍵點(diǎn)4:三角形尾隨矩形框

使用相對(duì)定位。能夠使三角形始終固定在矩形框的邊上。

position:relative;

所有代碼:

<html>
<head>
<style>
  /* bubble style */
        .sender{
            clear:both;
        }
        .sender div:nth-of-type(1){
            float: left;
        }
        .sender div:nth-of-type(2){
            background-color: aquamarine;
            float: left;
            margin: 0 20px 10px 15px;
            padding: 10px 10px 10px 0px;
            border-radius:7px;
        }

        .receiver div:first-child img,
        .sender div:first-child img{
            width:50px;
            height: 50px;
        }

        .receiver{
            clear:both;
        }
        .receiver div:nth-child(1){
            float: right;
        }
        .receiver div:nth-of-type(2){
            float:right;
            background-color: gold;
            margin: 0 10px 10px 20px;
            padding: 10px 0px 10px 10px;
            border-radius:7px;
        }

        .left_triangle{
            height:0px;  
            width:0px;  
            border-width:8px;  
            border-style:solid;  
            border-color:transparent aquamarine transparent transparent;  
            position: relative;
            left:-16px;
            top:3px;
        }

        .right_triangle{
            height:0px;  
            width:0px;  
            border-width:8px;  
            border-style:solid;  
            border-color:transparent transparent transparent gold;  
            position: relative;
            right:-16px;
            top:3px;
        }

  </style>
</head>
<body>
<!-- Left -->
<div class="sender">
      <div>
          <img src="chatTemplateExample2_files/cat.jpg">
      </div>
  <div>
      <div class="left_triangle"></div>
      <span> hello, man! </span>
   </div>
  </div>
<!-- Right -->
  <div class="receiver">
      <div>
          <img src="chatTemplateExample2_files/cat.jpg">
      </div>
   <div>
        <div class="right_triangle"></div>
        <span> hello world </span>
   </div>
  </div>  
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:甘南 紅河 營(yíng)口 萍鄉(xiāng) 文山 咸陽 蘇州 惠州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML5實(shí)現(xiàn)QQ聊天氣泡效果》,本文關(guān)鍵詞  HTML5,實(shí)現(xiàn),聊天,氣泡,效果,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HTML5實(shí)現(xiàn)QQ聊天氣泡效果》相關(guān)的同類信息!
  • 本頁收集關(guān)于HTML5實(shí)現(xiàn)QQ聊天氣泡效果的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    永福县| 同江市| 呈贡县| 罗平县| 大兴区| 布尔津县| 宁明县| 会理县| 兴山县| 二连浩特市| 库伦旗| 平武县| 成都市| 望江县| 永德县| 黔南| 二连浩特市| 阳新县| 贵定县| 佛山市| 沛县| 太保市| 常熟市| 丰原市| 册亨县| 兰考县| 宜黄县| 封丘县| 宁远县| 德令哈市| 濉溪县| 翁牛特旗| 肇源县| 绥江县| 中江县| 兴国县| 商水县| 郁南县| 墨玉县| 仙居县| 隆化县|