写一个漂亮的H5聊天界面
时间: 2023-11-28 10:50:14 浏览: 111
好的,以下是一个简单的H5聊天界面示例:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chat Interface</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
font-size: 16px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.chat-box {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.chat-box-header {
background-color: #f2f2f2;
padding: 10px;
text-align: center;
}
.chat-box-body {
padding: 10px;
max-height: 400px;
overflow-y: scroll;
}
.chat-box-message {
margin-bottom: 10px;
display: flex;
align-items: flex-start;
}
.chat-box-message-avatar {
width: 40px;
height: 40px;
margin-right: 10px;
border-radius: 50%;
overflow: hidden;
}
.chat-box-message-avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.chat-box-message-content {
background-color: #f2f2f2;
padding: 10px;
border-radius: 5px;
max-width: 60%;
}
.chat-box-message-content p {
margin: 0;
line-height: 1.5;
}
.chat-box-message-content .time {
font-size: 12px;
color: #999;
}
.chat-box-message-reverse {
flex-direction: row-reverse;
}
.chat-box-message-reverse .chat-box-message-content {
background-color: #0084ff;
color: #fff;
}
.chat-box-message-reverse .chat-box-message-content .time {
color: #c3c3c3;
}
.chat-box-input {
display: flex;
margin-top: 10px;
}
.chat-box-input input[type="text"] {
flex: 1;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
background-color: #f2f2f2;
margin-right: 10px;
outline: none;
}
.chat-box-input button {
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
background-color: #0084ff;
color: #fff;
cursor: pointer;
outline: none;
}
</style>
</head>
<body>
<div class="container">
<div class="chat-box">
<div class="chat-box-header">
<h3>Chat Interface</h3>
</div>
<div class="chat-box-body">
<div class="chat-box-message chat-box-message-reverse">
<div class="chat-box-message-avatar">
<img src="https://via.placeholder.com/40x40" alt="Avatar">
</div>
<div class="chat-box-message-content">
<p>Hello, how can I help you?</p>
<div class="time">12:30 PM</div>
</div>
</div>
<div class="chat-box-message">
<div class="chat-box-message-avatar">
<img src="https://via.placeholder.com/40x40" alt="Avatar">
</div>
<div class="chat-box-message-content">
<p>I need help with my account.</p>
<div class="time">12:31 PM</div>
</div>
</div>
<div class="chat-box-message chat-box-message-reverse">
<div class="chat-box-message-avatar">
<img src="https://via.placeholder.com/40x40" alt="Avatar">
</div>
<div class="chat-box-message-content">
<p>What seems to be the problem?</p>
<div class="time">12:32 PM</div>
</div>
</div>
</div>
<div class="chat-box-input">
<input type="text" placeholder="Type your message...">
<button>Send</button>
</div>
</div>
</div>
</body>
</html>
```
这个聊天界面有一个头部标题,一个消息框和一个输入框。消息框中包含了几个消息,每个消息包含了一个头像、一个消息内容和一个时间戳。输入框包含了一个文本输入框和一个发送按钮。样式使用了一些简单的 CSS,可以根据需要进行修改。
阅读全文