帮我基于html css js 生成一份聊天界面 样式类似于微信聊天界面
时间: 2023-10-04 11:08:51 浏览: 194
好的,我可以帮你生成一个类似于微信聊天界面的样式,你需要在你的HTML文件中加入以下代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Chat Interface</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f0f0f0;
}
.container {
width: 100%;
max-width: 800px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
box-sizing: border-box;
}
.message {
width: 100%;
position: relative;
margin-top: 10px;
margin-bottom: 10px;
padding: 10px;
display: flex;
flex-direction: column;
align-items: flex-start;
border-radius: 10px;
background-color: #fff;
box-shadow: 2px 2px 5px #e0e0e0;
}
.message.sent {
align-items: flex-end;
background-color: #dcf8c6;
}
.message.sent::before {
content: "";
position: absolute;
right: -10px;
top: 50%;
transform: translateY(-50%);
border-top: 10px solid transparent;
border-right: 10px solid #dcf8c6;
border-bottom: 10px solid transparent;
}
.message.received::before {
content: "";
position: absolute;
left: -10px;
top: 50%;
transform: translateY(-50%);
border-top: 10px solid transparent;
border-left: 10px solid #fff;
border-bottom: 10px solid transparent;
}
.message p {
margin: 0;
font-size: 16px;
line-height: 1.5;
}
.mine {
color: #00bfff;
}
.yours {
color: #000;
}
.input-box {
width: 100%;
position: fixed;
bottom: 0;
left: 0;
display: flex;
align-items: center;
background-color: #fff;
padding: 10px;
box-shadow: 2px -2px 5px #e0e0e0;
}
.input-box input[type="text"] {
flex: 1;
border: none;
padding: 10px;
font-size: 16px;
border-radius: 5px;
outline: none;
}
.input-box button {
border: none;
background-color: #00bfff;
color: #fff;
padding: 10px;
border-radius: 5px;
margin-left: 10px;
cursor: pointer;
outline: none;
}
</style>
</head>
<body>
<div class="container">
<div class="message received">
<p class="yours">Hi, how are you?</p>
</div>
<div class="message sent">
<p class="mine">I'm fine, thank you. And you?</p>
</div>
<div class="message received">
<p class="yours">I'm doing great!</p>
</div>
<!-- add more messages here -->
</div>
<div class="input-box">
<input type="text" placeholder="Type your message here...">
<button>Send</button>
</div>
</body>
</html>
```
这是一个简单的HTML文件,包含了一个聊天界面和输入框。你可以根据需要修改样式和添加更多消息。希望这可以帮到你!
阅读全文