0

0

高手教你如何制作一个简单漂亮的前端聊天界面

云罗郡主

云罗郡主

发布时间:2018-10-20 16:03:49

|

11998人浏览过

|

来源于csdn

转载

本篇文章给大家带来的内容是关于高手教你如何制作一个简单漂亮的前端聊天界面,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

    一个简单的前端静态聊天界面,实现了聊天的基本功能,目前后台还没做,接下来还会继续更新后台和完善前台样式并更新。

一.Html代码



    
    chat
    
    


  • 天狼星

    4-12-15:10

  • 天狼星

    4-12-15:10

  • 天狼星

    4-12-15:10

  • 天狼星

    4-12-15:10

二.CSS代码

    有些需要注意的地方已经标上注释了

* {
    margin: 0;
    padding: 0;
    font-size: 12px;
    font-family: "微软雅黑";
}

.all {
    width: 100%;
    height: 790px;
    /*background-color: #7fa4f2;*/
    background: linear-gradient(to right, #879eee, #ba78dc); /* 标准的语法 */

}

.chat_index {
    width: 1000px;
    height: 600px;
    border: 1px solid black;
    position: relative;
    top: 100px;
    margin: 0 auto;
}

.chat_banner {
    background: linear-gradient(to right, #a41adc, #ee1351, #a41adc); /* 标准的语法 */
    width: 999px;
    height: 50px;
    border: 1px solid blue;
}

.chat_body {
    width: 999px;
    height: 546px;
    border: 1px solid red;
}

.chat_online {
    overflow: hidden;
    float: left;
    height: 546px;
    width: 200px;
    border: 1px solid yellow;
    background-color: white;
}

.search_online {
    text-indent: 2em;
    height: 40px;
    border: 1px solid black;
}

.search_online input[type="text"] {
    outline: none;
    margin: 2px auto;
    height: 30px;
    width: 60%;
    border-radius: 8px;
    text-indent: 2em;
}

.online_friend ul li {

    list-style-type: none;
}

.online_friend ul li {

    height: 60px;
    border-bottom: 1px solid #1c1f21;
    margin-top: 10px;
}

.a_friend {

    /*border: 1px solid #2328ff;*/
    height: 55px;
    background-color: #39fffe;

}

.head_portrait {

    background-color: #b532ff;
    margin: 6px 6px;
    float: left;
    height: 40px;
    width: 40px;
    border: 1px solid orangered;
    border-radius: 50%;
}

.head_text {
    padding: 3px;
    font-size: 22px;
    text-align: center;
    vertical-align: center;
    margin-top: 3px;
}

.friend {

    float: right;
    height: 54px;
    width: 140px;
    /*border: 1px solid rebeccapurple;*/
}

.friend .name {

    margin: 4px 6px;
    float: left;
}

.friend .this_time {
    margin-top: 4px;
    float: right;
}

.chat_main {
    float: left;
    width: 548px;
    height: 546px;
    border: 1px solid seagreen;
    /*background-color: white;*/
    background: url("../img/圣诞.jpg") no-repeat;
    background-size: cover;
}

.send_message {
    width: 548px;
    height: 65px;
    position: absolute;
    bottom: 0px;
    background: linear-gradient(to top, rgba(9, 216, 237, 0.99), #72cad4);
}

.send_message input[type="text"] {
    width: 470px;
    height: 30px;
    margin-top: 16px;
    margin-left: 10px;
    border-radius: 10px 0 0 10px;
    text-indent: 2em;
    outline: none;
    background-color: white;
    border: none;
}

.send_message input[type="button"] {
    border-radius: 0 10px 10px 0;
    width: 35px;
    height: 30px;
    background-color: white;
    border: none;
    margin-left: 0;
    background-color: white;
    border: none;
    outline: none;

}

.send_message input[type="button"]:hover {
    background-color: orangered;
}

.send_message input[type="button"]:active {
    background-color: #879eee;
}

.chat_namecard {
    float: left;
    width: 245px;
    height: 546px;
    border: 1px solid saddlebrown;
    background-color: #f1fea9;
}


.chat_content ul{
list-style-type: none;
}
.chat_content{
    overflow: auto;
    width: 540px;
    /*设置高度滚动条才有效*/
    height: 470px;
}
.chat_content li{
    margin-top: 10px;
    width: 540px;
    clear: both;
    display: block;

}

.chat_content li img{
    margin: 6px 0 0 0;
}

.chat_content li span {
    background: #ffd351;
    padding: 10px;
    border-radius: 10px;
    /*最大宽度不能太长,不然布局会混乱*/
    max-width: 400px;
    border: 1px solid white;
    box-shadow: 0 0 3px #879eee;
    margin: 6px 10px 0 10px;
    overflow: hidden;
}

.chat_content li img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.chat_content li img.imgleft {
 margin-left: 10px;
    float: left;
}

.chat_content li img.imgright {
 margin-right: 10px;
    float: right;
}

.chat_content li span.spanleft {
    float: left;
}

.chat_content li span.spanright {
    float: right;
}
三.JS代码
window.onload = function () {
    var user = ["../img/img_17.jpg"];
    var num = 1;//判断左右
    var portrait_position = 0;
    var now = -1;//左右浮动
    var send_btn = document.getElementById('send_btn');
    var send_txt = document.getElementById('send_txt');
    var chat_ul = document.getElementById('chat_ul');
    var chat_span = chat_ul.getElementsByTagName('span');
    var chat_img = chat_ul.getElementsByTagName('img');
    send_btn.onclick = function () {
        if (send_txt.value == '') {
            alert("请不要惜字如金");
        } else {
            chat_ul.innerHTML += '
  • 高手教你如何制作一个简单漂亮的前端聊天界面' + send_txt.value + ''; now++; if (num==0) { chat_span[now].className = 'spanright'; chat_img[now].className = 'imgright'; } else { chat_span[now].className = 'spanleft'; chat_img[now].className = 'imgleft'; } send_txt.value = ''; // 内容过多时,将滚动条放置到最底端 /*contentcontent.scrollTop = content.scrollHeight;*/ } } }
  •     num 消息显示在左边还是右边,根据后台请求来操作

    四.界面截图

    20180604231952266.png

    PhotoG
    PhotoG

    PhotoG是全球首个内容营销端对端智能体

    下载

    以上就是对的全部介绍,如果您想了解更多有关HTML视频教程,请关注PHP中文网。

    立即学习前端免费学习笔记(深入)”;

    相关专题

    更多
    高德地图升级方法汇总
    高德地图升级方法汇总

    本专题整合了高德地图升级相关教程,阅读专题下面的文章了解更多详细内容。

    43

    2026.01.16

    全民K歌得高分教程大全
    全民K歌得高分教程大全

    本专题整合了全民K歌得高分技巧汇总,阅读专题下面的文章了解更多详细内容。

    84

    2026.01.16

    C++ 单元测试与代码质量保障
    C++ 单元测试与代码质量保障

    本专题系统讲解 C++ 在单元测试与代码质量保障方面的实战方法,包括测试驱动开发理念、Google Test/Google Mock 的使用、测试用例设计、边界条件验证、持续集成中的自动化测试流程,以及常见代码质量问题的发现与修复。通过工程化示例,帮助开发者建立 可测试、可维护、高质量的 C++ 项目体系。

    24

    2026.01.16

    java数据库连接教程大全
    java数据库连接教程大全

    本专题整合了java数据库连接相关教程,阅读专题下面的文章了解更多详细内容。

    35

    2026.01.15

    Java音频处理教程汇总
    Java音频处理教程汇总

    本专题整合了java音频处理教程大全,阅读专题下面的文章了解更多详细内容。

    16

    2026.01.15

    windows查看wifi密码教程大全
    windows查看wifi密码教程大全

    本专题整合了windows查看wifi密码教程大全,阅读专题下面的文章了解更多详细内容。

    56

    2026.01.15

    浏览器缓存清理方法汇总
    浏览器缓存清理方法汇总

    本专题整合了浏览器缓存清理教程汇总,阅读专题下面的文章了解更多详细内容。

    16

    2026.01.15

    ps图片相关教程汇总
    ps图片相关教程汇总

    本专题整合了ps图片设置相关教程合集,阅读专题下面的文章了解更多详细内容。

    9

    2026.01.15

    ppt一键生成相关合集
    ppt一键生成相关合集

    本专题整合了ppt一键生成相关教程汇总,阅读专题下面的的文章了解更多详细内容。

    26

    2026.01.15

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    Vue 教程
    Vue 教程

    共42课时 | 6.7万人学习

    JavaScript-网页的灵魂
    JavaScript-网页的灵魂

    共33课时 | 9万人学习

    直播系统及多人直播聊天室系统
    直播系统及多人直播聊天室系统

    共6课时 | 1.1万人学习

    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号