您可以直接复制下面的代码,保存为 .html 文件,然后用浏览器打开即可查看效果。

核心特性
- HTML5 语义化标签: 使用
<header>,<section>,<footer>,<article>等标签,使代码结构清晰,对搜索引擎友好。 - 现代化设计: 采用简洁、大气的卡片式布局,配色舒适。
- 响应式布局: 使用 CSS3 的 Flexbox 和媒体查询,完美适配各种屏幕尺寸。
- 平滑滚动: 点击导航菜单时,页面会平滑滚动到对应部分。
- 交互效果: 鼠标悬停时有微妙的动画效果,提升用户体验。
- 易于定制: 代码结构清晰,您只需要修改相应部分的内容即可。
完整源代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">张三 - 个人网站</title>
<style>
/* --- 全局样式 --- */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f4f7f6;
}
html {
scroll-behavior: smooth; /* 平滑滚动 */
}
.container {
max-width: 1100px;
margin: 0 auto;
padding: 0 20px;
}
h1, h2, h3 {
margin-bottom: 20px;
line-height: 1.2;
}
h2 {
text-align: center;
font-size: 2.5rem;
color: #2c3e50;
padding-bottom: 10px;
border-bottom: 2px solid #3498db;
display: inline-block;
margin-bottom: 50px;
}
/* --- 导航栏 --- */
header {
background: #fff;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
position: fixed;
width: 100%;
top: 0;
z-index: 1000;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 0;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
color: #3498db;
}
.nav-links {
display: flex;
list-style: none;
}
.nav-links li {
margin-left: 30px;
}
.nav-links a {
text-decoration: none;
color: #333;
font-weight: 500;
transition: color 0.3s ease;
}
.nav-links a:hover {
color: #3498db;
}
/* --- 主要内容区域 --- */
main {
margin-top: 80px; /* 为固定导航栏留出空间 */
}
section {
padding: 80px 0;
}
.section-content {
text-align: center;
}
/* --- 首页/英雄区域 --- */
#home {
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://images.unsplash.com/photo-1557804522-66403a2ba275?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1740&q=80') no-repeat center center/cover;
color: #fff;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.hero-content h1 {
font-size: 3.5rem;
margin-bottom: 20px;
}
.hero-content p {
font-size: 1.2rem;
margin-bottom: 30px;
}
.btn {
display: inline-block;
padding: 12px 30px;
background: #3498db;
color: #fff;
text-decoration: none;
border-radius: 5px;
border: none;
cursor: pointer;
font-size: 1rem;
transition: background 0.3s ease;
}
.btn:hover {
background: #2980b9;
}
/* --- 关于我 --- */
#about {
background: #fff;
}
.about-content {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap; /* 响应式 */
}
.about-text {
flex: 1;
padding-right: 40px;
}
.about-img {
flex: 1;
text-align: center;
}
.about-img img {
width: 300px;
height: 300px;
border-radius: 50%;
object-fit: cover;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
/* --- 技能 --- */
#skills {
background: #f4f7f6;
}
.skills-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 30px;
}
.skill-card {
background: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.skill-card:hover {
transform: translateY(-10px);
}
.skill-card i {
font-size: 3rem;
color: #3498db;
margin-bottom: 20px;
}
/* --- 项目 --- */
#projects {
background: #fff;
}
.projects-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 30px;
}
.project-card {
background: #fff;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.project-card:hover {
transform: translateY(-10px);
}
.project-img {
height: 200px;
overflow: hidden;
}
.project-img img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.project-card:hover .project-img img {
transform: scale(1.1);
}
.project-info {
padding: 20px;
}
.project-info h3 {
margin-bottom: 10px;
}
.project-links {
margin-top: 15px;
}
.project-links a {
color: #3498db;
text-decoration: none;
margin-right: 15px;
font-weight: 500;
}
/* --- 联系方式 --- */
#contact {
background: #f4f7f6;
text-align: center;
}
.contact-info {
display: flex;
justify-content: center;
gap: 40px;
margin-top: 30px;
flex-wrap: wrap;
}
.contact-item {
display: flex;
align-items: center;
gap: 10px;
}
.contact-item i {
font-size: 1.5rem;
color: #3498db;
}
/* --- 页脚 --- */
footer {
background: #2c3e50;
color: #fff;
text-align: center;
padding: 20px 0;
}
/* --- 响应式设计 --- */
@media (max-width: 768px) {
.nav-links {
display: none; /* 在移动端隐藏导航链接,可以配合JS实现汉堡菜单 */
}
.hero-content h1 {
