- 规划与设计:在写代码前,先想清楚要做什么。
- 基础HTML结构:搭建网站的骨架。
- CSS美化:给网站穿上漂亮的“衣服”。
- 高级功能与交互:添加一些动态效果。
- 部署与发布:让全世界都能看到你的作品。
- 完整代码示例:提供一个可以直接使用的简单模板。
第一步:规划与设计 (最重要的一步!)
在打开任何代码编辑器之前,先用纸笔或设计工具(如 Figma, Sketch, 甚至画图工具)规划好你的网站。

(图片来源网络,侵删)
明确目标 你的网站是给谁看的?目标是什么?
- 目标用户:招聘经理、潜在客户、其他开发者?
- 核心目标:找到工作、获得项目合作、展示个人品牌? 规划** 确定网站需要包含哪些页面和内容模块。
- 首页:欢迎语、个人简介、核心技能、精选作品展示。
- 关于我:更详细的个人介绍、工作经历、教育背景、兴趣爱好。
- 作品集:这是核心!详细展示你的每个项目。
每个项目应有:项目名称、截图/GIF/视频、技术栈、项目链接、项目描述。
- 联系方式:你的邮箱、社交媒体链接(GitHub, LinkedIn, Twitter等)、或一个简单的联系表单。
设计风格
- 简洁现代:通常以白色/深色为背景,搭配少量亮色点缀,排版清晰。
- 创意独特:适用于设计师、艺术家等,可以有更丰富的动效和布局。
- 专业商务:适合求职,色调沉稳,内容严谨。
技术选型

(图片来源网络,侵删)
- 纯HTML/CSS/JavaScript:最基础,可控性最高,适合学习和理解原理。
- 前端框架:如 Bootstrap, Tailwind CSS,它们提供了大量预设的样式和组件,能让你快速搭建出响应式、美观的网站,强烈推荐初学者使用。
- 现代前端框架:如 React, Vue,功能强大,适合构建复杂的单页应用,但学习曲线较陡。
本教程将采用纯HTML + Tailwind CSS 的方式,因为它能兼顾学习效果和开发效率。
第二步:基础HTML结构
HTML是网页的骨架,它定义了内容的结构。
- 创建文件:创建一个名为
index.html的文件。 - 基本模板:所有HTML文件都遵循这个基本结构。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">我的作品集 - 张三</title>
<!-- 这里我们将引入Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<!-- 网站内容都写在这里 -->
<h1>你好,世界!</h1>
</body>
</html>
关键标签解释:
<!DOCTYPE html>:声明这是一个HTML5文档。<html>:根元素,包裹整个页面。<head>:包含页面的元数据,如标题、字符编码、引入的样式表等。<title>:浏览器标签页上显示的标题。<body>:包含所有可见的页面内容,如文本、图片、链接等。
第三步:CSS美化 (使用Tailwind CSS)
Tailwind CSS是一个实用优先的CSS框架,你不需要写单独的CSS文件,直接在HTML元素的 class 属性中写样式即可。
首页布局示例
让我们构建一个简单的首页,包含导航栏、欢迎区域和作品展示。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">张三的个人作品集</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- 引入一个字体,比如Google Fonts的Noto Sans SC -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<style>
/* 自定义字体 */
body {
font-family: 'Noto Sans SC', sans-serif;
}
</style>
</head>
<body class="bg-gray-50 text-gray-800">
<!-- 导航栏 -->
<nav class="bg-white shadow-sm">
<div class="max-w-6xl mx-auto px-4">
<div class="flex justify-between h-16">
<div class="flex-shrink-0 flex items-center">
<a href="#" class="font-bold text-xl">张三</a>
</div>
<div class="hidden md:flex items-center space-x-8">
<a href="#about" class="hover:text-blue-600">关于我</a>
<a href="#portfolio" class="hover:text-blue-600">作品集</a>
<a href="#contact" class="hover:text-blue-600">联系方式</a>
</div>
</div>
</div>
</nav>
<!-- 主要内容区 -->
<main>
<!-- 欢迎区域 -->
<section class="bg-gradient-to-r from-blue-500 to-indigo-600 text-white py-20">
<div class="max-w-6xl mx-auto px-4 text-center">
<h1 class="text-4xl md:text-6xl font-bold mb-4">
你好,我是张三
</h1>
<p class="text-xl md:text-2xl mb-8">
一名充满热情的前端开发工程师
</p>
<a href="#portfolio" class="inline-block bg-white text-blue-600 px-8 py-3 rounded-full font-semibold hover:bg-gray-100 transition">
查看我的作品
</a>
</div>
</section>
<!-- 作品展示区 -->
<section id="portfolio" class="py-20">
<div class="max-w-6xl mx-auto px-4">
<h2 class="text-3xl font-bold text-center mb-12">我的作品</h2>
<!-- 作品网格 -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<!-- 作品卡片 1 -->
<div class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition">
<img src="https://via.placeholder.com/400x250" alt="项目1截图" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold mb-2">电商网站重构</h3>
<p class="text-gray-600 mb-4">使用React和Node.js重构了一个老旧的电商平台,提升了50%的页面加载速度。</p>
<div class="flex flex-wrap gap-2 mb-4">
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">React</span>
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">Node.js</span>
<span class="bg-purple-100 text-purple-800 text-xs px-2 py-1 rounded">MongoDB</span>
</div>
<div class="flex space-x-4">
<a href="#" class="text-blue-600 hover:underline">在线预览</a>
<a href="#" class="text-gray-600 hover:underline">源代码</a>
</div>
</div>
</div>
<!-- 作品卡片 2 -->
<div class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition">
<img src="https://via.placeholder.com/400x250" alt="项目2截图" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold mb-2">任务管理App</h3>
<p class="text-gray-600 mb-4">一个简洁优雅的移动端任务管理应用,支持拖拽排序和提醒功能。</p>
<div class="flex flex-wrap gap-2 mb-4">
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">Vue.js</span>
<span class="bg-yellow-100 text-yellow-800 text-xs px-2 py-1 rounded">Vuetify</span>
</div>
<div class="flex space-x-4">
<a href="#" class="text-blue-600 hover:underline">在线预览</a>
<a href="#" class="text-gray-600 hover:underline">源代码</a>
</div>
</div>
</div>
<!-- 作品卡片 3 -->
<div class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition">
<img src="https://via.placeholder.com/400x250" alt="项目3截图" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold mb-2">数据可视化看板</h3>
<p class="text-gray-600 mb-4">为企业打造的数据实时监控看板,使用D3.js实现复杂的图表交互。</p>
<div class="flex flex-wrap gap-2 mb-4">
<span class="bg-orange-100 text-orange-800 text-xs px-2 py-1 rounded">D3.js</span>
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">TypeScript</span>
<span class="bg-gray-100 text-gray-800 text-xs px-2 py-1 rounded">WebSocket</span>
</div>
<div class="flex space-x-4">
<a href="#" class="text-blue-600 hover:underline">在线预览</a>
<a href="#" class="text-gray-600 hover:underline">源代码</a>
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- 页脚 -->
<footer class="bg-gray-800 text-white py-8">
<div class="max-w-6xl mx-auto px-4 text-center">
<p>© 2025 张三. All rights reserved.</p>
</div>
</footer>
</body>
</html>
代码解析:
class属性:这是Tailwind的核心。bg-gray-50设置背景色,text-gray-800设置文字颜色,py-20设置上下内边距。- 响应式设计:通过
md:(中等屏幕以上)、lg:(大屏幕以上) 前缀来实现。grid-cols-1 md:grid-cols-2表示在小屏幕上显示1列,在中等以上屏幕显示2列。 - Flexbox布局:
flex,justify-between,items-center等类用于灵活地对齐和排列元素,非常适合导航栏和按钮组。 - 语义化标签:
<nav>,<main>,<section>,<footer>等标签让HTML结构更清晰,对SEO和可访问性都有好处。
第四步:高级功能与交互
一个优秀的作品集网站需要一些交互来吸引用户。
平滑滚动
当点击导航链接时,页面会平滑地滚动到对应部分,而不是跳转。
在<head>中添加以下JavaScript代码:
<script>
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
</script>
联系表单
使用 Netlify Forms 或 Formspree 等第三方服务可以非常轻松地添加一个无需后端的联系表单。
以 Formspree 为例:
- 在 Formspree 注册并创建一个表单,获取
form的actionURL。 - 在HTML中创建表单:
<form action="https://formspree.io/f/YOUR_FORM_ID" method="POST" class="space-y-4">
<div>
<label for="name" class="block mb-1">姓名</label>
<input type="text" id="name" name="name" required class="w-full px-3 py-2 border border-gray-300 rounded-md">
</div>
<div>
<label for="email" class="block mb-1">邮箱</label>
<input type="email" id="email" name="email" required class="w-full px-3 py-2 border border-gray-300 rounded-md">
</div>
<div>
<label for="message" class="block mb-1">留言</label>
<textarea id="message" name="message" rows="5" required class="w-full px-3 py-2 border border-gray-300 rounded-md"></textarea>
</div>
<button type="submit" class="bg-blue-600 text-white px-6 py-2 rounded-md hover:bg-blue-700">发送</button>
</form>
添加动效
可以使用 AOS (Animate On Scroll) 库为页面元素添加滚动时的进入动画。
- 在
<head>中引入AOS的CSS和JS:<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet"> <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
- 在
<body>结束标签前初始化AOS:<script> AOS.init(); </script>
- 在任何HTML元素上添加
data-aos属性即可,<h2 data-aos="fade-up">我的作品</h2> <div data-aos="fade-up" data-aos-delay="100">...</div>
第五步:部署与发布
网站做好了,需要放到服务器上才能被访问。
GitHub Pages (免费,适合个人项目)
- 将你的代码上传到 GitHub 仓库。
- 进入仓库的
Settings->Pages。 - 在
Source部分,选择Deploy from a branch,选择main分支,文件夹选择/ (root)。 - 点击
Save,稍等片刻,你的网站就会通过https://<你的用户名>.github.io/<你的仓库名>这个地址上线了!
Netlify (免费,功能强大)
- 将你的代码上传到 GitHub 仓库。
- 注册一个 Netlify 账号,并连接你的 GitHub 仓库。
- Netlify 会自动检测到这是一个静态网站,并开始构建和部署。
- 你会得到一个随机的
.netlify.app域名,也可以绑定自己的域名。
Vercel (免费,对React/Vue等框架支持极佳) 流程与 Netlify 类似,也是连接GitHub仓库即可自动部署。
第六步:完整代码示例
这是一个包含了所有上述元素的、更完整的 index.html 文件,你可以直接复制、修改并使用它。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">张三的个人作品集</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<style>
body { font-family: 'Noto Sans SC', sans-serif; }
</style>
</head>
<body class="bg-gray-50 text-gray-800">
<!-- 导航栏 -->
<nav class="bg-white shadow-sm sticky top-0 z-50">
<div class="max-w-6xl mx-auto px-4">
<div class="flex justify-between h-16">
<div class="flex-shrink-0 flex items-center">
<a href="#" class="font-bold text-xl">张三</a>
</div>
<div class="hidden md:flex items-center space-x-8">
<a href="#about" class="hover:text-blue-600 transition">关于我</a>
<a href="#portfolio" class="hover:text-blue-600 transition">作品集</a>
<a href="#contact" class="hover:text-blue-600 transition">联系方式</a>
</div>
</div>
</div>
</nav>
<main>
<!-- 欢迎区域 -->
<section class="bg-gradient-to-r from-blue-500 to-indigo-600 text-white py-20">
<div class="max-w-6xl mx-auto px-4 text-center" data-aos="fade-up">
<h1 class="text-4xl md:text-6xl font-bold mb-4">
你好,我是张三
</h1>
<p class="text-xl md:text-2xl mb-8">
一名充满热情的前端开发工程师
</p>
<a href="#portfolio" class="inline-block bg-white text-blue-600 px-8 py-3 rounded-full font-semibold hover:bg-gray-100 transition">
查看我的作品
</a>
</div>
</section>
<!-- 关于我 -->
<section id="about" class="py-20 bg-white">
<div class="max-w-6xl mx-auto px-4" data-aos="fade-up">
<h2 class="text-3xl font-bold text-center mb-12">关于我</h2>
<div class="flex flex-col md:flex-row items-center gap-8">
<img src="https://via.placeholder.com/200x200" alt="个人头像" class="w-48 h-48 rounded-full object-cover">
<div class="flex-1">
<p class="text-lg leading-relaxed mb-4">
我是一名拥有3年前端开发经验的工程师,专注于构建高性能、用户友好的Web应用。
我热爱学习新技术,并对代码质量和用户体验有极致的追求。
</p>
<p class="text-lg leading-relaxed">
在工作之余,我喜欢参与开源项目,并通过写博客来分享我的学习心得。
</p>
</div>
</div>
</div>
</section>
<!-- 作品展示区 -->
<section id="portfolio" class="py-20">
<div class="max-w-6xl mx-auto px-4">
<h2 class="text-3xl font-bold text-center mb-12" data-aos="fade-up">我的作品</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
<!-- 作品卡片 1 -->
<div class="bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition" data-aos="fade-up" data-aos-delay="100">
<img src="https://via.placeholder.com/400x250" alt="项目1截图" class="w-full h-48 object-cover">
<div class="p-6">
<h3 class="text-xl font-bold mb-2">电商网站重构</h3>
<p class="text-gray-600 mb-4">使用React和Node.js重构了一个老旧的电商平台,提升了50%的页面加载速度。</p>
<div class="flex flex-wrap gap-2 mb-4">
<span class="bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">React</span>
<span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded">Node.js</span>
</div>
<div class="flex space-x-4">
<a href="#" class="text-blue-600 hover:underline">在线预览</a>
<a href="#" class="text-gray-600 hover:underline">源代码</a>
</div>
</div>
</div>
<!-- ... 其他作品卡片 ... -->
</div>
</div>
</section>
<!-- 联系方式 -->
<section id="contact" class="py-20 bg-white">
<div class="max-w-3xl mx-auto px-4 text-center" data-aos="fade-up">
<h2 class="text-3xl font-bold mb-8">联系我</h2>
<p class="text-lg mb-8">如果你对我的作品感兴趣,或者有任何合作机会,欢迎随时与我联系!</p>
<form action="https://formspree.io/f/YOUR_FORM_ID" method="POST" class="max-w-md mx-auto space-y-4">
<div>
<input type="text" name="name" placeholder="你的姓名" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<input type="email" name="email" placeholder="你的邮箱" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<textarea name="message" placeholder="你的留言" rows="5" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
</div>
<button type="submit" class="w-full bg-blue-600 text-white px-6 py-2 rounded-md hover:bg-blue-700 transition">发送留言</button>
</form>
</div>
</section>
</main>
<!-- 页脚 -->
<footer class="bg-gray-800 text-white py-8">
<div class="max-w-6xl mx-auto px-4 text-center">
<p>© 2025 张三. All rights reserved.</p>
</div>
</footer>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
AOS.init({
duration: 800,
once: true
});
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
</script>
</body>
</html>
总结与建议
- 从模仿开始:不要害怕模仿优秀的设计,上面的模板就是一个很好的起点。
- 内容为王:再华丽的网站也比不上高质量的项目展示,确保你的项目描述清晰、技术栈准确、链接有效。
- 持续更新:你的作品集是活的,随着你完成新项目,要不断更新它。
- 注意细节:检查错别字、确保所有链接都能正常打开、在不同设备上测试网站的外观。
- 保持简洁:除非你是UI/UX设计师,否则不要过度设计,一个干净、快速、易于浏览的网站通常是最好的。
希望这份详细的指南能帮助你成功打造出属于自己的作品集网站!祝你成功!
