html css聊天界面,html/css实现聊天布局

效果图

162ca7a017b953b66d08b2c89474c83d.png

项目结构

30b8b12beb679e0fa67bd91455b9cfa0.png

html代码

img.jpeg

爱你呦

2019-5-17

img.jpeg

哈哈哈哈哈

img.jpeg

干嘛呢

img.jpeg

吃饭饭

确定

css

/*

聊天item采用flex布局

*/

.item {

display: flex;

margin-bottom: 10px;

}

.left {

flex-direction: row;

}

.right {

flex-direction: row-reverse;

}

.right .message {

margin-right: 10px;

}

.left .message{

margin-left: 10px;

}

.header-img {

width: 42px;

height: 42px;

border-radius: 100px;

}

.message {

border-radius: 10px;

display: flex;

background: #efefef;

min-height: 25px;

padding: 9px 10px;

align-items: center;

color: #222121;

}

.input-box {

position: absolute;

bottom: 0px;

left: 0;

right: 0;

display: flex;

padding: 4px 6px;

box-sizing: border-box;

}

.input-box input {

flex: 1;

border-radius: 10px;

border: 1px #cecece solid;

padding: 3px 4px;

outline: none;

}

.input-box button {

width: 80px;

background: #2196f4;

border-radius: 21px;

border: 1px #fffa solid;

color: #ffffff;

margin: 0px 6px;

outline: none;

}

button:active{}

.chart-timer{

text-align: center;

color: #616161;

font-size: 13px;

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要安装Vue.js和Vue CLI。在安装完成后,你可以使用Vue CLI创建一个新的Vue项目: ```bash vue create my-chat-app ``` 然后,在你的项目目录中,你可以创建一个名为`Chat.vue`的组件,这个组件将会显示聊天界面。在这个组件中,你可以使用Vue的数据绑定功能来绑定聊天记录和输入框的值。 ```vue <template> <div class="chat"> <div class="chat-history"> <div class="message" v-for="(message, index) in messages" :key="index"> <div class="message-content">{{ message.content }}</div> <div class="message-time">{{ message.time }}</div> </div> </div> <div class="chat-input"> <input type="text" v-model="inputMessage" @keyup.enter="sendMessage"> <button @click="sendMessage">Send</button> </div> </div> </template> <script> export default { data() { return { messages: [], inputMessage: "", }; }, methods: { sendMessage() { const time = new Date().toLocaleTimeString(); const content = this.inputMessage; this.messages.push({ content, time }); this.inputMessage = ""; }, }, }; </script> ``` 在这个组件中,我们有一个`messages`数组,它将会存储聊天记录。我们还有一个`inputMessage`变量,用来存储用户输入的内容。在`sendMessage`方法中,我们将用户输入的内容添加到`messages`数组中,并清空输入框的值。 接下来,你可以在你的应用程序中使用这个组件来显示聊天界面。 ```vue <template> <div class="app"> <chat></chat> </div> </template> <script> import Chat from "./components/Chat.vue"; export default { components: { Chat, }, }; </script> ``` 最后,你可以使用CSS样式来美化你的聊天界面。 ```css .chat { display: flex; flex-direction: column; height: 100%; } .chat-history { flex: 1; overflow: auto; } .message { display: flex; flex-direction: column; margin: 10px; } .message-content { background-color: #eee; padding: 10px; border-radius: 10px; max-width: 60%; } .message-time { font-size: 12px; text-align: right; } .chat-input { display: flex; align-items: center; } .chat-input input[type="text"] { flex: 1; height: 30px; margin-right: 10px; border-radius: 5px; border: none; padding: 5px; } .chat-input button { background-color: #4caf50; color: #fff; border: none; border-radius: 5px; padding: 5px 10px; } ``` 以上是一个简单的Vue.js微信聊天界面的开发过程,你可以根据你的需求进行相应的修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值