做一个论坛网页给我 HTML编写 单文件 功能齐全 界面美观
- User
做一个论坛网页给我 HTML编写 单文件 功能齐全 界面美观
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
做一个论坛网页给我 HTML编写 单文件 功能齐全 界面美观
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
我来为您创建一个功能齐全、界面美观的单文件论坛网页。这个论坛包含了发帖、回复、搜索、用户系统等核心功能。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>简约论坛</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
/* 头部样式 */
header {
background-color: #2c3e50;
color: white;
padding: 1rem 0;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
position: sticky;
top: 0;
z-index: 1000;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
}
.user-info {
display: flex;
align-items: center;
gap: 1rem;
}
.btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s;
}
.btn-primary {
background-color: #3498db;
color: white;
}
.btn-primary:hover {
background-color: #2980b9;
}
.btn-secondary {
background-color: #95a5a6;
color: white;
}
.btn-secondary:hover {
background-color: #7f8c8d;
}
/* 主要内容区域 */
main {
margin-top: 2rem;
min-height: calc(100vh - 200px);
}
/* 搜索栏 */
.search-bar {
background-color: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 2rem;
}
.search-form {
display: flex;
gap: 1rem;
}
.search-input {
flex: 1;
padding: 0.75rem;
border: 2px solid #e0e0e0;
border-radius: 5px;
font-size: 1rem;
transition: border-color 0.3s;
}
.search-input:focus {
outline: none;
border-color: #3498db;
}
/* 帖子列表 */
.post-list {
background-color: white;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
overflow: hidden;
}
.post-item {
padding: 1.5rem;
border-bottom: 1px solid #e0e0e0;
transition: background-color 0.3s;
cursor: pointer;
}
.post-item:hover {
background-color: #f8f9fa;
}
.post-item:last-child {
border-bottom: none;
}
.post-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
.post-title {
font-size: 1.2rem;
font-weight: 600;
color: #2c3e50;
}
.post-meta {
display: flex;
gap: 1rem;
color: #7f8c8d;
font-size: 0.9rem;
}
.post-content {
color: #555;
margin-bottom: 0.5rem;
}
.post-stats {
display: flex;
gap: 1.5rem;
color: #7f8c8d;
font-size: 0.9rem;
}
/* 新建帖子表单 */
.new-post-form {
background-color: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 2rem;
display: none;
}
.form-group {
margin-bottom: 1.5rem;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: #2c3e50;
}
.form-input, .form-textarea {
width: 100%;
padding: 0.75rem;
border: 2px solid #e0e0e0;
border-radius: 5px;
font-size: 1rem;
transition: border-color 0.3s;
}
.form-input:focus, .form-textarea:focus {
outline: none;
border-color: #3498db;
}
.form-textarea {
min-height: 150px;
resize: vertical;
}
/* 帖子详情 */
.post-detail {
background-color: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 2rem;
display: none;
}
.post-detail-header {
border-bottom: 2px solid #e0e0e0;
padding-bottom: 1rem;
margin-bottom: 1.5rem;
}
.post-detail-title {
font-size: 1.8rem;
font-weight: 700;
color: #2c3e50;
margin-bottom: 0.5rem;
}
.post-detail-content {
font-size: 1.1rem;
line-height: 1.8;
color: #444;
margin-bottom: 2rem;
}
/* 回复区域 */
.replies-section {
margin-top: 2rem;
}
.replies-header {
font-size: 1.3rem;
font-weight: 600;
margin-bottom: 1rem;
color: #2c3e50;
}
.reply-item {
background-color: #f8f9fa;
padding: 1rem;
border-radius: 5px;
margin-bottom: 1rem;
}
.reply-form {
margin-top: 2rem;
padding-top: 2rem;
border-top: 2px solid #e0e0e0;
}
/* 登录/注册模态框 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 2000;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: white;
padding: 2rem;
border-radius: 10px;
width: 90%;
max-width: 400px;
position: relative;
}
.modal-close {
position: absolute;
top: 1rem;
right: 1rem;
font-size: 1.5rem;
cursor: pointer;
color: #7f8c8d;
}
.modal-close:hover {
color: #2c3e50;
}
.modal-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 1.5rem;
color: #2c3e50;
}
/* 响应式设计 */
@media (max-width: 768px) {
.header-content {
flex-direction: column;
gap: 1rem;
}
.search-form {
flex-direction: column;
}
.post-header {
flex-direction: column;
align-items: flex-start;
gap: 0.5rem;
}
.post-stats {
flex-wrap: wrap;
}
}
/* 标签样式 */
.tag {
display: inline-block;
padding: 0.25rem 0.5rem;
background-color: #e0e0e0;
color: #555;
border-radius: 3px;
font-size: 0.8rem;
margin-right: 0.5rem;
}
.tag-hot {
background-color: #e74c3c;
color: white;
}
.tag-new {
background-color: #2ecc71;
color: white;
}
/* 分页 */
.pagination {
display: flex;
justify-content: center;
gap: 0.5rem;
margin-top: 2rem;
}
.page-btn {
padding: 0.5rem 1rem;
border: 1px solid #e0e0e0;
background-color: white;
color: #333;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.page-btn:hover {
background-color: #3498db;
color: white;
border-color: #3498db;
}
.page-btn.active {
background-color: #3498db;
color: white;
border-color: #3498db;
}
</style>
</head>
<body>
<!-- 头部 -->
<header>
<div class="container">
<div class="header-content">
<div class="logo">简约论坛</div>
<div class="user-info">
<button class="btn btn-primary" onclick="showNewPostForm()">发新帖</button>
<span id="username">游客</span>
<button class="btn btn-secondary" onclick="showLoginModal()">登录</button>
<button class="btn btn-secondary" onclick="showRegisterModal()">注册</button>
</div>
</div>
</div>
</header>
<!-- 主要内容 -->
<main class="container">
<!-- 搜索栏 -->
<div class="search-bar">
<form class="search-form" onsubmit="searchPosts(event)">
<input type="text" class="search-input" placeholder="搜索帖子..." id="searchInput">
<button type="submit" class="btn btn-primary">搜索</button>
</form>
</div>
<!-- 新建帖子表单 -->
<div class="new-post-form" id="newPostForm">
<h2 style="margin-bottom: 1.5rem;">发表新帖子</h2>
<form onsubmit="createPost(event)">
<div class="form-group">
<label class="form-label">标题</label>
<input type="text" class="form-input" id="postTitle" required>
</div>
<div class="form-group">
<label class="form-label">内容</label>
<textarea class="form-textarea" id="postContent" required></textarea>
</div>
<div class="form-group">
<label class="form-label">标签(用空格分隔)</label>
<input type="text" class="form-input" id="postTags" placeholder="例如: 技术 生活 分享">
</div>
<div style="display: flex; gap: 1rem;">
<button type="submit" class="btn btn-primary">发布</button>
<button type="button" class="btn btn-secondary" onclick="hideNewPostForm()">取消</button>
</div>
</form>
</div>
<!-- 帖子详情 -->
<div class="post-detail" id="postDetail">
<button class="btn btn-secondary" onclick="showPostList()">返回列表</button>
<div class="post-detail-header">
<h1 class="post-detail-title" id="detailTitle"></h1>
<div class="post-meta">
<span id="detailAuthor"></span>
<span id="detailTime"></span>
<span id="detailViews"></span>
</div>
</div>
<div class="post-detail-content" id="detailContent"></div>
<div class="replies-section">
<h3 class="replies-header">回复 (<span id="replyCount">0</span>)</h3>
<div id="repliesList"></div>
<form class="reply-form" onsubmit="addReply(event)">
<div class="form-group">
<label class="form-label">发表回复</label>
<textarea class="form-textarea" id="replyContent" required></textarea>
</div>
<button type="submit" class="btn btn-primary">提交回复</button>
</form>
</div>
</div>
<!-- 帖子列表 -->
<div class="post-list" id="postList"></div>
<!-- 分页 -->
<div class="pagination" id="pagination"></div>
</main>
<!-- 登录模态框 -->
<div class="modal" id="loginModal">
<div class="modal-content">
<span class="modal-close" onclick="closeModal('loginModal')">×</span>
<h2 class="modal-title">登录</h2>
<form onsubmit="login(event)">
<div class="form-group">
<label class="form-label">用户名</label>
<input type="text" class="form-input" id="loginUsername" required>
</div>
<div class="form-group">
<label class="form-label">密码</label>
<input type="password" class="form-input" id="loginPassword" required>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">登录</button>
</form>
</div>
</div>
<!--