用html写一个聊天界面
时间: 2023-05-17 07:06:31 浏览: 74
html5+css3 聊天系统界面
4星 · 用户满意度95%
可以使用HTML和CSS来创建一个简单的聊天界面,以下是一个示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Chat Interface</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
font-size: 14px;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.message {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
margin-bottom: 10px;
padding: 10px;
position: relative;
width: 60%;
}
.message:before {
content: "";
position: absolute;
top: 10px;
left: -10px;
border-top: 10px solid transparent;
border-right: 10px solid #fff;
border-bottom: 10px solid transparent;
border-left: none;
}
.message:after {
content: "";
position: absolute;
top: 10px;
left: -12px;
border-top: 10px solid transparent;
border-right: 10px solid rgba(0, 0, 0, 0.1);
border-bottom: 10px solid transparent;
border-left: none;
}
.message.incoming {
background-color: #e6e6e6;
float: left;
}
.message.incoming:before {
left: auto;
right: -10px;
border-right: none;
border-left: 10px solid #e6e6e6;
}
.message.incoming:after {
left: auto;
right: -12px;
border-right: none;
border-left: 10px solid rgba(0, 0, 0, 0.1);
}
.message.outgoing {
background-color: #0084ff;
color: #fff;
float: right;
}
.message.outgoing:before {
left: auto;
right: -10px;
border-right: none;
border-left: 10px solid #0084ff;
}
.message.outgoing:after {
left: auto;
right: -12px;
border-right: none;
border-left: 10px solid rgba(0, 0, 0, 0.1);
}
.message .time {
color: #999;
font-size: 12px;
margin-top: 5px;
text-align: right;
}
.message .text {
margin-top: 5px;
word-wrap: break-word;
}
.form {
margin-top: 20px;
text-align: center;
}
.form input[type="text"] {
border: none;
border-radius: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
font-size: 14px;
padding: 10px 20px;
width: 60%;
}
.form input[type="submit"] {
background-color: #0084ff;
border: none;
border-radius: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
color: #fff;
cursor: pointer;
font-size: 14px;
padding: 10px 20px;
margin-left: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="message incoming">
<div class="text">Hello! How can I help you today?</div>
<div class="time">10:00 AM</div>
</div>
<div class="message outgoing">
<div class="text">Hi! I have a question about your product.</div>
<div class="time">10:01 AM</div>
</div>
<div class="message incoming">
<div class="text">Sure, what's your question?</div>
<div class="time">10:02 AM</div>
</div>
<div class="form">
<input type="text" placeholder="Type your message here...">
<input type="submit" value="Send">
</div>
</div>
</body>
</html>
```
这个聊天界面使用了两种不同的样式来区分发送方和接收方的消息。消息的时间也被包含在每个消息中。最后,一个简单的表单用于输入新的消息。
阅读全文