模板特点
- 响应式设计:在电脑、平板和手机上都能完美显示。
- 现代简约风格:采用卡片式布局和柔和的配色,视觉上清爽舒适。
- 单页应用体验:通过 JavaScript 实现平滑的页面滚动和导航切换,无需刷新页面。
- 模块化结构:代码结构清晰,方便您添加或删除模块(如技能、项目、联系方式等)。
- 交互效果:包含导航高亮、技能条动画、滚动显示动画等细节。
最终效果预览
您可以想象一个这样的页面:

(图片来源网络,侵删)
第一步:HTML 代码 (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>
<link rel="stylesheet" href="style.css">
<!-- 引入字体图标库,这里使用 Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar">
<div class="nav-container">
<a href="#home" class="nav-logo">张三</a>
<ul class="nav-menu">
<li class="nav-item">
<a href="#home" class="nav-link active">首页</a>
</li>
<li class="nav-item">
<a href="#about" class="nav-link">关于我</a>
</li>
<li class="nav-item">
<a href="#skills" class="nav-link">技能</a>
</li>
<li class="nav-item">
<a href="#projects" class="nav-link">项目</a>
</li>
<li class="nav-item">
<a href="#contact" class="nav-link">联系我</a>
</li>
</ul>
<div class="hamburger">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</div>
</div>
</nav>
<!-- 主要内容区 -->
<main>
<!-- 首页/个人介绍 -->
<section id="home" class="section active">
<div class="container">
<div class="hero-content">
<div class="hero-text">
<h1>你好,我是 <span class="highlight">张三</span></h1>
<p class="subtitle">一名充满热情的前端开发工程师</p>
<p>我专注于创建美观、快速且用户友好的网络体验。</p>
<div class="hero-buttons">
<a href="#contact" class="btn btn-primary">联系我</a>
<a href="#projects" class="btn btn-secondary">查看作品</a>
</div>
</div>
<div class="hero-image">
<img src="https://via.placeholder.com/400x400" alt="张三的头像">
</div>
</div>
</div>
</section>
<!-- 关于我 -->
<section id="about" class="section">
<div class="container">
<h2 class="section-title">关于我</h2>
<div class="about-content">
<div class="about-text">
<p>我是一名拥有3年经验的前端开发工程师,毕业于XX大学计算机科学专业,我热爱编程,享受将复杂问题转化为优雅解决方案的过程。</p>
<p>在工作中,我注重代码质量和用户体验,善于与团队成员沟通协作,共同推动项目前进,我相信,好的产品源于细节的打磨和对技术的不断探索。</p>
<p>除了编程,我还喜欢阅读、摄影和徒步旅行,这些爱好让我保持创造力和对生活的热情。</p>
</div>
<div class="about-info">
<div class="info-item">
<i class="fas fa-user"></i>
<span>张三</span>
</div>
<div class="info-item">
<i class="fas fa-map-marker-alt"></i>
<span>中国, 北京</span>
</div>
<div class="info-item">
<i class="fas fa-envelope"></i>
<span>zhangsan@example.com</span>
</div>
<div class="info-item">
<i class="fab fa-github"></i>
<a href="https://github.com/zhangsan" target="_blank">github.com/zhangsan</a>
</div>
</div>
</div>
</div>
</section>
<!-- 技能 -->
<section id="skills" class="section">
<div class="container">
<h2 class="section-title">我的技能</h2>
<div class="skills-container">
<div class="skill-item">
<div class="skill-info">
<span class="skill-name">HTML / CSS</span>
<span class="skill-level">95%</span>
</div>
<div class="skill-bar">
<div class="skill-progress" data-skill="95"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-info">
<span class="skill-name">JavaScript</span>
<span class="skill-level">90%</span>
</div>
<div class="skill-bar">
<div class="skill-progress" data-skill="90"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-info">
<span class="skill-name">React / Vue</span>
<span class="skill-level">85%</span>
</div>
<div class="skill-bar">
<div class="skill-progress" data-skill="85"></div>
</div>
</div>
<div class="skill-item">
<div class="skill-info">
<span class="skill-name">Node.js</span>
<span class="skill-level">75%</span>
</div>
<div class="skill-bar">
<div class="skill-progress" data-skill="75"></div>
</div>
</div>
</div>
</div>
</section>
<!-- 项目 -->
<section id="projects" class="section">
<div class="container">
<h2 class="section-title">我的项目</h2>
<div class="projects-grid">
<div class="project-card">
<img src="https://via.placeholder.com/600x400" alt="项目1截图" class="project-image">
<div class="project-info">
<h3>电商网站</h3>
<p>一个功能完整的响应式电商平台,包含商品展示、购物车、用户中心等模块。</p>
<div class="project-tech">
<span>React</span>
<span>Redux</span>
<span>Ant Design</span>
</div>
<div class="project-links">
<a href="#" class="btn btn-small"><i class="fas fa-external-link-alt"></i> 预览</a>
<a href="https://github.com/zhangsan/project1" target="_blank" class="btn btn-small btn-outline"><i class="fab fa-github"></i> 代码</a>
</div>
</div>
</div>
<div class="project-card">
<img src="https://via.placeholder.com/600x400" alt="项目2截图" class="project-image">
<div class="project-info">
<h3>任务管理应用</h3>
<p>一个基于 Vue.js 的在线任务管理工具,支持任务创建、编辑、分类和完成状态追踪。</p>
<div class="project-tech">
<span>Vue.js</span>
<span>Element UI</span>
<span>Node.js</span>
</div>
<div class="project-links">
<a href="#" class="btn btn-small"><i class="fas fa-external-link-alt"></i> 预览</a>
<a href="https://github.com/zhangsan/project2" target="_blank" class="btn btn-small btn-outline"><i class="fab fa-github"></i> 代码</a>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- 联系我 -->
<section id="contact" class="section">
<div class="container">
<h2 class="section-title">联系我</h2>
<div class="contact-content">
<p>如果您对我的工作感兴趣,或者有任何问题,欢迎随时与我联系!</p>
<div class="contact-links">
<a href="mailto:zhangsan@example.com" class="contact-link">
<i class="fas fa-envelope"></i>
<span>zhangsan@example.com</span>
</a>
<a href="https://linkedin.com/in/zhangsan" target="_blank" class="contact-link">
<i class="fab fa-linkedin"></i>
<span>LinkedIn</span>
</a>
<a href="https://github.com/zhangsan" target="_blank" class="contact-link">
<i class="fab fa-github"></i>
<span>GitHub</span>
</a>
<a href="https://twitter.com/zhangsan" target="_blank" class="contact-link">
<i class="fab fa-twitter"></i>
<span>Twitter</span>
</a>
</div>
</div>
</div>
</section>
</main>
<!-- 页脚 -->
<footer>
<div class="container">
<p>© 2025 张三. All rights reserved.</p>
</div>
</footer>
<script src="script.js"></script>
</body>
</html>
第二步:CSS 代码 (style.css)
这是页面的样式表,负责美化页面,使其看起来美观、专业。
/* --- 全局样式 --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
:root {
--primary-color: #3498db;
--secondary-color: #2c3e50;
--text-color: #333;
--light-text: #777;
--bg-color: #f4f4f4;
--card-bg: #fff;
--shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
font-family: 'Poppins', sans-serif;
line-height: 1.6;
color: var(--text-color);
background-color: var(--bg-color);
}
.container {
max-width: 1100px;
margin: 0 auto;
padding: 0 20px;
}
.section {
padding: 80px 0;
display: none;
}
.section.active {
display: block;
}
.section-title {
text-align: center;
font-size: 2.5rem;
margin-bottom: 3rem;
color: var(--secondary-color);
}
/* --- 导航栏 --- */
.navbar {
position: fixed;
top: 0;
width: 100%;
background-color: var(--card-bg);
box-shadow: var(--shadow);
z-index: 1000;
transition: all 0.3s ease;
}
.nav-container {
max-width: 1100px;
margin: 0 auto;
padding: 0 20px;
display: flex;
justify-content: space-between;
align-items: center;
height: 70px;
}
.nav-logo {
font-size: 1.5rem;
font-weight: 700;
color: var(--primary-color);
text-decoration: none;
}
.nav-menu {
display: flex;
list-style: none;
}
.nav-link {
color: var(--text-color);
text-decoration: none;
font-weight: 500;
margin-left: 30px;
transition: color 0.3s ease;
}
.nav-link:hover, .nav-link.active {
color: var(--primary-color);
}
.hamburger {
display: none;
cursor: pointer;
}
.bar {
display: block;
width: 25px;
height: 3px;
margin: 5px auto;
background-color: var(--text-color);
transition: all 0.3s ease-in-out;
}
/* --- 首页 --- */
.hero-content {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
}
.hero-text {
flex: 1;
min-width: 300px;
padding-right: 40px;
}
.hero-text h1 {
font-size: 3rem;
margin-bottom: 1rem;
}
.hero-text .highlight {
color: var(--primary-color);
}
.hero-text .subtitle {
font-size: 1.2rem;
color: var(--light-text);
margin-bottom: 1rem;
}
.hero-buttons {
margin-top: 2rem;
}
.btn {
display: inline-block;
padding: 12px 25px;
margin-right: 15px;
border-radius: 50px;
text-decoration: none;
font-weight: 500;
transition: all 0.3s ease;
border: 2px solid transparent;
}
.btn-primary {
background-color: var(--primary-color);
color: white;
}
.btn-primary:hover {
background-color: #2980b9;
transform: translateY(-3px);
}
.btn-secondary {
background-color: transparent;
color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-secondary:hover {
background-color: var(--primary-color);
color: white;
}
.hero-image {
flex: 1;
min-width: 300px;
text-align: center;
}
.hero-image img {
width: 100%;
max-width: 400px;
border-radius: 50%;
box-shadow: var(--shadow);
}
/* --- 关于我 --- */
.about-content {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 40px;
}
.about-text {
flex: 2;
min-width: 300px;
}
.about-info {
flex: 1;
min-width: 250px;
background-color: var(--card-bg);
padding: 30px;
border-radius: 10px;
box-shadow: var(--shadow);
}
.info-item {
margin-bottom: 15px;
display: flex;
align-items: center;
}
.info-item i {
margin-right: 10px;
color: var(--primary-color);
width: 20px;
}
.info-item a {
color: var(--primary-color);
text-decoration: none;
}
/* --- 技能 --- */
.skills-container {
max-width: 800px;
margin: 0 auto;
}
.skill-item {
margin-bottom: 25px;
}
.skill-info {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}
.skill-name {
font-weight: 600;
}
.skill-level {
color: var(--light-text);
}
.skill-bar {
background-color: #e0e0e0;
height: 10px;
border-radius: 5px;
overflow: hidden;
}
.skill-progress {
height: 100%;
background-color: var(--primary-color);
width: 0;
transition: width 2s ease-in-out;
}
/* --- 项目 --- */
.projects-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 30px;
}
.project-card {
background-color: var(--card-bg);
border-radius: 10px;
overflow: hidden;
box-shadow: var(--shadow);
transition: transform 0.3s ease;
}
.project-card:hover {
transform: translateY(-10px);
}
.project-image {
width: 100%;
height: 200px;
object-fit: cover;
}
.project-info {
padding: 25px;
}
.project-info h3 {
margin-bottom: 10px;
color: var(--secondary-color);
}
.project-tech {
margin: 15px 0;
}
.project-tech span {
display: inline-block;
background-color: var(--bg-color);
color: var(--primary-color);
padding: 5px 12px;
border-radius: 20px;
font-size: 0.85rem;
margin-right: 8px;
}
.project-links {
margin-top: 20px;
}
.btn-small {
padding: 8px 15px;
font-size: 0.9rem;
margin-right: 10px;
}
.btn-outline {
background-color: transparent;
border: 2px solid var(--primary-color);
color: var(--primary-color);
}
.btn-outline:hover {
background-color: var(--primary-color);
color: white;
}
/* --- 联系我 --- */
.contact-content {
text-align: center;
max-width: 600px;
margin: 0 auto;
}
.contact-links {
margin-top: 30px;
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 20px;
}
.contact-link {
display: flex;
align-items: center;
padding: 15px 25px;
background-color: var(--card-bg);
color: var(--text-color);
text-decoration: none;
border-radius: 50px;
box-shadow: var(--shadow);
transition: all 0.3s ease;
}
.contact-link:hover {
background-color: var(--primary-color);
color: white;
transform: translateY(-5px);
}
.contact-link i {
margin-right: 10px;
font-size: 1.2rem;
}
/* --- 页脚 --- */
footer {
background-color: var(--secondary-color);
color: white;
text-align: center;
padding: 20px 0;
}
/* --- 响应式设计 --- */
@media (max-width: 768px) {
.hamburger {
display: block;
}
.nav-menu {
position: fixed;
left: -100%;
top: 70px;
flex-direction: column;
background-color: var(--card-bg);
width: 100%;
text-align: center;
transition: 0.3s;
box-shadow: var(--shadow);
padding: 20px 0;
}
.nav-menu.active {
left: 0;
}
.nav-item {
margin: 10px 0;
}
.hero-content {
text-align: center;
}
.hero-text {
padding-right: 0;
margin-bottom: 30px;
}
.hero-text h1 {
font-size: 2.2rem;
}
.section {
padding: 60px 0;
}
.section-title {
font-size: 2rem;
}
}
第三步:JavaScript 代码 (script.js)
这是页面的交互逻辑,主要负责导航栏的响应式切换、页面滚动时的导航高亮、以及技能条的动画效果。
// 等待 DOM 加载完成
document.addEventListener('DOMContentLoaded', () => {
// --- 导航栏功能 ---
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
// 点击汉堡菜单,切换移动端菜单的显示/隐藏
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
});
// 点击导航链接后,关闭移动端菜单
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
navMenu.classList.remove('active');
}));
// --- 页面滚动与导航高亮 ---
const sections = document.querySelectorAll('.section');
const navLinks = document.querySelectorAll('.nav-link');
// 滚动事件监听
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollY >= (sectionTop - 200)) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href').slice(1) === current) {
link.classList.add('active');
}
});
});
// --- 技能条动画 ---
const skillBars = document.querySelectorAll('.skill-progress');
// 检查元素是否在视口中
const isInViewport = (element) => {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
// 动画函数
const animateSkills = () => {
skillBars.forEach(bar => {
if (isInViewport(bar)) {
const skill = bar.getAttribute('data-skill');
bar.style.width = skill + '%';
}
});
};
// 初始检查和滚动时检查
animateSkills();
window.addEventListener('scroll', animateSkills);
});
如何使用这个模板
-
创建文件:在您的电脑上创建一个文件夹,
my-portfolio,在这个文件夹中,创建三个文件:index.html、style.css和script.js,并将上面的代码分别复制粘贴进去。
(图片来源网络,侵删) -
:打开
index.html文件,将所有张三、zhangsan@example.com、https://github.com/zhangsan等占位符信息替换成您自己的真实信息。 -
添加图片:
- 头像:将一张您的个人照片命名为
profile.jpg(或任何您喜欢的名字),放在my-portfolio文件夹中,然后修改index.html中<img src="https://via.placeholder.com/400x400" alt="张三的头像">这一行,将其src属性改为src="profile.jpg"。 - 项目截图:为您的每个项目准备一张截图,同样放在
my-portfolio文件夹中,并修改index.html中对应的<img>标签的src属性。
- 头像:将一张您的个人照片命名为
-
扩展或修改:
- 添加新模块:如果您想添加一个“博客”或“工作经历”模块,只需在
index.html的<main>标签内添加一个新的<section>,并确保它有一个唯一的id,然后在style.css中为其添加样式,在script.js中可能需要添加滚动逻辑。 - 修改样式:您可以直接在
style.css中修改颜色、字体、间距等,以打造您独特的风格,修改root中的--primary-color可以改变整个页面的主题色。
- 添加新模块:如果您想添加一个“博客”或“工作经历”模块,只需在
-
预览:直接用浏览器打开
index.html文件,您就可以看到您的个人主页了,要部署到网上,您可以将这个文件夹上传到任何静态网站托管服务,如 GitHub Pages, Netlify, Vercel 等。
(图片来源网络,侵删)
