You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Project_CampusLostAndFoundP.../聊天.html

181 lines
5.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模仿微信的聊天界面</title>
<style>
/* CSS样式用于页面布局和样式 */
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
.chat-container {
max-width: 800px; /* 增加最大宽度 */
margin: 20px auto;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
padding: 20px;
}
.message {
display: flex;
margin-bottom: 20px;
}
.user-avatar {
width: 40px;
height: 40px;
background-color: #4caf50;
border-radius: 50%;
margin-right: 10px;
}
.message-content {
background-color: #e0e0e0;
border-radius: 10px;
padding: 10px;
max-width: 70%;
}
.user-message {
align-self: flex-end;
background-color: #c4ffd2;
}
.other-user-message {
align-self: flex-start;
background-color: #cfd8dc;
}
.nickname {
font-weight: bold;
margin-bottom: 5px;
}
/* 输入框样式,与微信相似 */
.input-container {
display: flex;
align-items: center;
background-color: #fff;
border-radius: 25px;
border: 1px solid #ccc;
padding: 10px;
margin-top: 20px;
}
.input-container input[type="text"] {
flex-grow: 1;
border: none;
outline: none;
padding: 10px;
font-size: 16px;
}
.input-container button {
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
cursor: pointer;
}
/* 添加更多消息 */
.message-time {
font-size: 12px;
color: #888;
align-self: flex-end;
margin-left: 10px;
}
/* 更多用户头像和昵称 */
.user-avatar.friend {
background-color: #2196F3;
}
.nickname.friend {
color: #2196F3;
}
/* 返回按钮样式 */
.back-button {
background-color: #4caf50; /* 修改背景颜色为绿色 */
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
margin: 20px; /* 修改位置为上下左右各20px */
cursor: pointer;
position: absolute; /* 设置为绝对定位 */
top: 0; /* 距离顶部距离为0 */
left: 0; /* 距离左侧距离为0 */
}
/* CSS结束 */
</style>
</head>
<body>
<div class="chat-container">
<div class="message other-user-message">
<div class="user-avatar friend"></div>
<div>
<div class="nickname friend">好友的昵称</div>
<div class="message-content">你好,这是好友的消息。</div>
<div class="message-time">09:30 AM</div>
</div>
</div>
<div class="message user-message">
<div class="user-avatar"></div>
<div>
<div class="nickname">您的昵称</div>
<div class="message-content">你好,这是您的消息。</div>
<div class="message-time">09:35 AM</div>
</div>
</div>
<!-- 添加更多消息 -->
<div class="message other-user-message">
<div class="user-avatar friend"></div>
<div>
<div class="nickname friend">好友的昵称</div>
<div class="message-content">这是好友的另一条消息。</div>
<div class="message-time">09:40 AM</div>
</div>
</div>
<!-- 更多用户消息 -->
<div class="message user-message">
<div class="user-avatar"></div>
<div>
<div class="nickname">您的昵称</div>
<div class="message-content">这是您的另一条消息,稍微长一些,用于测试消息框的自动调整长度。</div>
<div class="message-time">09:45 AM</div>
</div>
</div>
<!-- 输入框 -->
<div class="input-container">
<input type="text" placeholder="在这里输入消息">
<button>&#9658;</button>
</div>
</div>
<!-- 返回按钮 -->
<button class="back-button" onclick="goBack()">返回</button>
<script>
// 返回按钮的点击事件
function goBack() {
window.history.back();
}
</script>
</body>
</html>