好的,这是一个完全包含在单个HTML文件中的仿Outlook邮箱界面。它使用了内联的CSS和JavaScript,无需任何外部文件或服务器。
主要功能:
- 单文件设计:所有代码 (HTML, CSS, JavaScript) 都在一个
.html 文件中。
- 仿Outlook布局:经典的三栏式布局(文件夹、邮件列表、阅读窗格)。
- 动态内容:使用JavaScript动态加载和显示邮件。
- 交互功能:
- 点击邮件列表中的邮件,会在右侧阅读窗格中显示其内容。
- 邮件被点击后会自动标记为已读(加粗样式消失)。
- 当前选中的邮件会高亮显示。
- 响应式提示:虽然未完全实现移动端优化,但基本布局在桌面浏览器上效果最佳。
如何使用
- 将下面的所有代码复制。
- 粘贴到一个新的文本文件中。
- 将该文件另存为
outlook_clone.html (或任何以 .html 结尾的名称)。
- 用你的网页浏览器(如Chrome, Firefox, Edge)打开这个文件。
代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>单文件HTML邮箱界面 (仿Outlook)</title>
<style>
/* --- 1. 全局和布局样式 --- */
:root {
--primary-color: #0078d4;
--border-color: #e1e1e1;
--hover-bg-color: #f0f0f0;
--selected-bg-color: #c7e0f4;
--font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
html, body {
margin: 0;
padding: 0;
height: 100vh;
overflow: hidden;
font-family: var(--font-family);
font-size: 14px;
color: #333;
}
.email-client-container {
display: grid;
grid-template-columns: 220px 350px 1fr;
height: 100%;
width: 100%;
}
/* --- 2. 各窗格样式 --- */
.pane {
height: 100vh;
border-right: 1px solid var(--border-color);
display: flex;
flex-direction: column;
overflow: hidden;
}
.pane-header {
padding: 15px;
font-weight: 600;
font-size: 16px;
border-bottom: 1px solid var(--border-color);
flex-shrink: 0;
}
.pane-content {
overflow-y: auto;
flex-grow: 1;
}
/* --- 3. 左侧文件夹窗格 --- */
#folder-pane .new-email-btn {
display: block;
width: calc(100% - 30px);
margin: 15px;
padding: 10px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 4px;
font-size: 14px;
cursor: pointer;
text-align: center;
}
#folder-pane .new-email-btn:hover {
background-color: #005a9e;
}
.folder-list {
list-style: none;
padding: 0;
margin: 0;
}
.folder-list li {
padding: 12px 15px;
cursor: pointer;
display: flex;
align-items: center;
}
.folder-list li:hover {
background-color: var(--hover-bg-color);
}
.folder-list li.active {
background-color: var(--selected-bg-color);
font-weight: 600;
border-left: 3px solid var(--primary-color);
padding-left: 12px;
}
.folder-icon {
margin-right: 10px;
width: 16px;
height: 16px;
}
/* --- 4. 中间邮件列表窗格 --- */
#message-list-pane {
background-color: #fafafa;
}
#message-list-pane .pane-content {
padding: 0;
}
.email-item {
padding: 15px;
border-bottom: 1px solid var(--border-color);
cursor: pointer;
}
.email-item:hover {
background-color: var(--hover-bg-color);
}
.email-item.selected {
background-color: var(--selected-bg-color);
}
.email-item .sender,
.email-item .subject {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.email-item .sender {
font-weight: 600;
margin-bottom: 4px;
}
.email-item .timestamp {
float: right;
font-size: 12px;
color: #666;
}
.email-item .subject {
font-size: 14px;
margin-bottom: 4px;
}
.email-item .snippet {
font-size: 13px;
color: #555;
}
.email-item.unread .sender,
.email-item.unread .subject {
font-weight: 900; /* Bold for unread */
color: #000;
}
.email-item.read .sender {
font-weight: normal; /* Normal for read */
}
.email-item.read .subject {
font-weight: normal;
}
/* --- 5. 右侧阅读窗格 --- */
#reading-pane {
border-right: none;
}
#reading-pane .pane-content {
padding: 20px;
}
#reading-pane-placeholder {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
color: #888;
text-align: center;
}
.email-subject {
font-size: 24px;
margin-bottom: 20px;
font-weight: 400;
}
.email-meta {
display: flex;
align-items: center;
margin-bottom: 25px;
padding-bottom: 20px;
border-bottom: 1px solid var(--border-color);
}
.sender-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
background-color: var(--primary-color);
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
font-weight: bold;
margin-right: 15px;
}
.sender-info .name {
font-weight: 600;
}
.sender-info .email, .sender-info .date {
font-size: 13px;
color: #666;
}
.email-body {
line-height: 1.7;
white-space: pre-wrap; /* Respect newlines in the email body */
}
</style>
</head>
<body>
<div class="email-client-container">
<!-- 左侧文件夹窗格 -->
<aside id="folder-pane" class="pane">
<header class="pane-header">文件夹</header>
<button class="new-email-btn">新邮件</button>
<div class="pane-content">
<ul class="folder-list">
<li class="active">
<svg class="folder-icon" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M2048 576v1088q0 40-28 68t-68 28H68q-40 0-68-28t-28-68V384q0-40 28-68t68-28h448l128 128h1280q40 0 68 28t28 68z"/></svg>
收件箱
</li>
<li>
<svg class="folder-icon" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M1792 640v960H256V640l768 512l768-512zm128-224v128l-896 597L128 544V416q0-40 28-68t68-28h1536q40 0 68 28t28 68z"/></svg>
已发送邮件
</li>
<li>
<svg class="folder-icon" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M1920 1792V928l-384-384H384V256h1024v512h512zM256 0q-40 0-68 28t-28 68v1664q0 40 28 68t68 28h1536q40 0 68-28t28-68V768L1408 0H256z"/></svg>
草稿
</li>
<li>
<svg class="folder-icon" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M768 384h512V256H768v128zm384 1280H896v128h256v-128zm768-640V512h-256V256H384v256H128v512l192 192v256h128v-256h1024v256h128v-256l192-192zM256 896h1536V640H256v256z"/></svg>
垃圾邮件
</li>
</ul>
</div>
</aside>
<!-- 中间邮件列表窗格 -->
<main id="message-list-pane" class="pane">
<header class="pane-header">收件箱</header>
<div id="message-list" class="pane-content">
<!-- 邮件项将由JavaScript动态插入此处 -->
</div>
</main>
<!-- 右侧阅读窗格 -->
<section id="reading-pane" class="pane">
<div id="reading-pane-content" class="pane-content">
<!-- 邮件内容将由JavaScript动态插入此处 -->
<div id="reading-pane-placeholder">
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 5H4C3.44772 5 3 5.44772 3 6V18C3 18.5523 3.44772 19 4 19H20C20.5523 19 21 18.5523 21 18V6C21 5.44772 20.5523 5 20 5Z" stroke="#cccccc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 6L12 12.5L21 6" stroke="#cccccc" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<p>选择一封邮件进行阅读</p>
</div>
</div>
</section>
</div>
<script>
// --- 1. 测试数据 ---
const testEmails = [
{
id: 1,
sender: 'GitHub',
subject: '新版本发布通知:v3.2.1',
timestamp: '今天 09:30',
body: `你好!
我们很高兴地通知您,我们的项目已发布新版本 v3.2.1。
此版本包含重要的安全更新和性能改进。
建议您尽快更新。
谢谢,
GitHub团队`,
read: false
},
{
id: 2,
sender: '项目经理 - 李华',
subject: '关于下周项目会议的提醒',
timestamp: '昨天 17:15',
body: `大家好,
提醒一下,下周一上午10点我们将召开项目启动会议。
请提前准备好相关材料。
会议议程已发送至日历。
祝好,
李华`,
read: false
},
{
id: 3,
sender: 'Trello',
subject: '您有新的任务分配',
timestamp: '昨天 14:00',
body: `您在 “网站重构” 看板中被分配到了新的任务:
“完成用户登录页面的UI设计”。
截止日期:本周五。
请登录Trello查看详情。`,
read: true
},
{
id: 4,
sender: 'HR部门',
subject: '2024年节假日安排通知',
timestamp: '2024/04/28',
body: `全体员工:
根据国家法定节假日规定,现将2024年劳动节放假安排通知如下:
5月1日至5月5日放假调休,共5天。4月27日(星期六)、4月28日(星期日)上班。
请大家提前安排好工作生活。
祝大家节日快乐!
人力资源部`,
read: true
},
{
id: 5,
sender: '前端技术周刊',
subject: '探索最新的前端框架和工具',
timestamp: '2024/04/26',
body: `本周周刊要点:
- React 19 新特性前瞻
- Vue Vapor Mode 深度解析
- Bun vs. Node.js: 性能对决
点击链接阅读全文。`,
read: true
}
];
// --- 2. DOM 元素引用 ---
const messageListContainer = document.getElementById('message-list');
const readingPaneContent = document.getElementById('reading-pane-content');
const readingPanePlaceholder = document.getElementById('reading-pane-placeholder');
// --- 3. 核心功能函数 ---
/**
* 渲染邮件列表
*/
function renderMessageList() {
messageListContainer.innerHTML = ''; // 清空列表
testEmails.forEach(email => {
const emailItem = document.createElement('div');
emailItem.className = `email-item ${email.read ? 'read' : 'unread'}`;
emailItem.dataset.id = email.id; // 使用 data-id 存储邮件ID
const snippet = email.body.split('\n')[0].substring(0, 50) + '...';
emailItem.innerHTML = `
<span class="timestamp">${email.timestamp}</span>
<div class="sender">${email.sender}</div>
<div class="subject">${email.subject}</div>
<div class="snippet">${snippet}</div>
`;
messageListContainer.appendChild(emailItem);
});
}
/**
* 显示指定ID的邮件内容
* @param {number} emailId
*/
function displayEmail(emailId) {
const email = testEmails.find(e => e.id === emailId);
if (!email) return;
// 隐藏占位符
readingPanePlaceholder.style.display = 'none';
// 生成发件人头像的缩写
const senderInitial = email.sender.charAt(0).toUpperCase();
// 更新阅读窗格内容
readingPaneContent.innerHTML = `
<h2 class="email-subject">${email.subject}</h2>
<div class="email-meta">
<div class="sender-avatar">${senderInitial}</div>
<div class="sender-info">
<div class="name">${email.sender}</div>
<div class="date">发送于:${email.timestamp}</div>
</div>
</div>
<div class="email-body">${email.body}</div>
`;
// 标记为已读
email.read = true;
// 更新邮件列表中的样式
updateMessageListSelection(emailId);
}
/**
* 更新邮件列表中的选中和已读状态
* @param {number} selectedId
*/
function updateMessageListSelection(selectedId) {
const allItems = messageListContainer.querySelectorAll('.email-item');
allItems.forEach(item => {
const itemId = parseInt(item.dataset.id);
const email = testEmails.find(e => e.id === itemId);
// 更新选中状态
if (itemId === selectedId) {
item.classList.add('selected');
} else {
item.classList.remove('selected');
}
// 更新已读/未读状态
if (email && email.read) {
item.classList.remove('unread');
item.classList.add('read');
}
});
}
// --- 4. 事件监听 ---
// 使用事件委托来处理邮件列表的点击事件
messageListContainer.addEventListener('click', (event) => {
const clickedItem = event.target.closest('.email-item');
if (clickedItem) {
const emailId = parseInt(clickedItem.dataset.id);
displayEmail(emailId);
}
});
// --- 5. 初始化 ---
document.addEventListener('DOMContentLoaded', () => {
renderMessageList();
});
</script>
</body>
</html>