h5 聊天界面实例
时间: 2023-08-20 21:06:03 浏览: 109
html5聊天页面
好的,以下是一个简单的基于HTML5和CSS3的聊天窗口示例,您可以在此基础上进行修改和扩展:
HTML部分:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>聊天室</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="chat">
<div class="messages">
<div class="message received">
<div class="avatar"></div>
<div class="text">你好!</div>
</div>
<div class="message sent">
<div class="avatar"></div>
<div class="text">你好!</div>
</div>
<div class="message received">
<div class="avatar"></div>
<div class="text">最近怎么样?</div>
</div>
</div>
<div class="input">
<input type="text" placeholder="请输入消息...">
<button>发送</button>
</div>
</div>
</body>
</html>
```
CSS部分:
```css
.chat {
width: 400px;
height: 500px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
border-radius: 10px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.messages {
flex: 1;
padding: 10px;
overflow-y: scroll;
}
.message {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.received {
flex-direction: row;
}
.sent {
flex-direction: row-reverse;
}
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
margin-right: 10px;
}
.text {
background: #eee;
padding: 10px;
border-radius: 10px;
max-width: 70%;
word-wrap: break-word;
}
.input {
display: flex;
align-items: center;
padding: 10px;
}
input {
flex: 1;
height: 40px;
padding: 0 10px;
border-radius: 20px;
border: none;
outline: none;
}
button {
height: 40px;
width: 60px;
background: #0084ff;
color: #fff;
border: none;
outline: none;
border-radius: 20px;
margin-left: 10px;
cursor: pointer;
}
```
此聊天窗口使用flex布局实现,包含消息列表和输入框两个部分,消息列表使用overflow-y: scroll实现滚动效果,消息分为接收和发送两种类型。您可以通过修改CSS样式来自定义聊天窗口的外观和布局。
阅读全文