濮阳杆衣贸易有限公司

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

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

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

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

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

步驟1:布局
 

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

右側消息,相同先清除浮動。然后設置 float:right,這樣用戶圖標和消息顯示在同一行了。當中圖標在最右邊。圖標左側是消息。

步驟2:設置圓角矩形

border-radius:7px;     

步驟3:三角形箭頭
&n

將DIV的寬度和高度設置為0,設置邊框寬度,能夠使其表現(xiàn)出一個由四個三角形組成的矩形,每一個三角形的顏色和大小能夠通過設置border寬度和顏色設置。

這里將當中三個三角形顏色設置為透明。僅僅留下一個三角形可見。

    .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;
    }

關鍵點4:三角形尾隨矩形框

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

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>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

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

巨人網(wǎng)絡通訊聲明:本文標題《HTML5實現(xiàn)QQ聊天氣泡效果》,本文關鍵詞  HTML5,實現(xiàn),聊天,氣泡,效果,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《HTML5實現(xiàn)QQ聊天氣泡效果》相關的同類信息!
  • 本頁收集關于HTML5實現(xiàn)QQ聊天氣泡效果的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    贡觉县| 郁南县| 芦山县| 龙胜| 榆社县| 诸城市| 绥江县| 江北区| 上犹县| 连城县| 昆山市| 乌拉特中旗| 黎川县| 恭城| 常山县| 呼图壁县| 临颍县| 江口县| 新巴尔虎右旗| 兰坪| 绥芬河市| 张家界市| 巧家县| 延寿县| 巩留县| 古浪县| 吉林市| 泰兴市| 德安县| 武鸣县| 黎川县| 额尔古纳市| 尼勒克县| 罗平县| 惠水县| 洛川县| 红安县| 定安县| 综艺| 滨海县| 湟源县|