不使用flex布局,使用float实现聊天框对话功能,兼容性写法

该博客介绍了一个项目需求,需要兼容到IE9,因此不能使用flex布局。作者展示了如何利用float属性来实现聊天框的对话功能,包括左右两侧用户的聊天内容展示,时间戳显示,以及输入框和发送按钮的布局。代码中包含HTML结构和对应的CSS样式,确保在多种浏览器上正常显示。
摘要由CSDN通过智能技术生成

不使用flex布局,使用float实现聊天框对话功能,兼容性写法

IE10+、Edge、Firefox 2+、Chrome 4+、Safari 3.1+支持flex布局
项目要求兼容到ie9 所以只能写float来实现聊天框功能

页面
<div class="left-container">
    <div class="contact-container" ref="replyContainer" v-if="chatList.length>0">
        <div class="items" :key="index" v-for="(item,index) in chatList">
          <div class="clearfix" :class="[item.flag == 1?'left':'right']" >
            <div class="info">
              <div class="avatar"></div>
              <span class="name">{{item.flag==1?chat.sideName:chat.myName}}</span>
            </div>
            <div class="content" style="height:100%">
              {{item.content}}
            </div>
            <div class="time">{{item.createTime}}</div>
          </div> 
        </div>
      </div>
      <div class="send-container">
        <div class="clearfix">
          <a-input class="leaveWord" placeholder="请输入留言" v-model="content" @keyup.enter="send" v-placeholder></a-input>
          <a-button class="sendButton" type="primary" @click="send">发送</a-button>
        </div>
      </div>
    </div>
css
.left-container{
  width: 100%;
  border: 1px solid rgb(238, 236, 236);
  border-radius: 6px;
  position: relative;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  .contact-container{
    padding: 20px;
    margin-bottom: 50px;
    min-height: 700px;
    max-height: 800px;
    overflow: auto;
    .items{
      width: 100%;
      margin-bottom: 20px;
      .info{
        width: 100%;
        height: 40px;
        margin-bottom: 4px;
        .avatar{
          width: 40px;
          height: 40px;
          border: 0.01rem solid #ccc;
          border-radius: 50%;
          float: left;
        }
        .name{
          font-size: 14px;
          line-height: 40px;
          color: #4d4c4c;
          margin:0 10px;
          white-space: nowrap;
        }
      }
      .content{
        max-width: 70%;
        border: 1px solid rgba(143, 141, 141, 0.1);
        background-color: rgba(153, 152, 152, 0.1);
        box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
        border-radius: 5px;
        padding: 10px 16px;
        word-break: break-all;
        font-size: 14px;
        color: #595959;
      }
      .time{
        width: 100%;
        text-align: center;
        font-size: 12px;
        margin-top:10px;
        color: #8e8d8d;
      }
    }
    .items .left {
      .info, .time{
        float: left;
      }
      .content{
        float: left;
        margin-left: 46px;
      }
    }
    .items .right {
      .info{
        float: right;
        .avatar,.name{
          float: right;
        }
      }
      .content{
        float: right;
        margin-left: 46px;
        margin-right: 50px;
      }
      .time{
        float: right;
      }
    }
    .items:nth-last-child(1){
      margin-bottom: 44px;
    }
  }
  .send-container{
    position: absolute;
    bottom: 10px;
    width: 100%;
    div{
      margin: 0 4%;
      .leaveWord{
        width: 84%;
        margin-right: 2%;
      }
      .sendButton{
        width: 14%;
        float: right;
      }
    } 
  }
}
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值