
基础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>个人主页</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>你的名字</h1>
<p>职业/身份简介</p>
</header>
<main>
<section class="about">
<h2>关于我</h2>
<p>这里写一段自我介绍。</p>
</section>
<section class="skills">
<h2>技能</h2>
<ul>
<li>HTML/CSS</li>
<li>其他技能项</li>
</ul>
</section>
</main>
<footer>
<p>联系邮箱:example@email.com</p>
</footer>
</body>
</html>
基础CSS样式
在styles.css中定义样式,从布局到细节逐步完善:
/* 全局样式 */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
color: #333;
background-color: #f4f4f4;
}
/* 页眉样式 */
header {
background: #35424a;
color: #ffffff;
padding: 20px 0;
text-align: center;
}
header h1 {
margin: 0;
}
/* 主要内容区 */
main {
padding: 20px;
max-width: 800px;
margin: 0 auto;
}
section {
margin-bottom: 20px;
background: #ffffff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h2 {
color: #35424a;
border-bottom: 2px solid #e8491d;
padding-bottom: 5px;
}
/* 列表样式 */
ul {
list-style-type: none;
padding: 0;
}
ul li {
padding: 5px 0;
}
/* 页脚样式 */
footer {
text-align: center;
padding: 10px;
background: #35424a;
color: #ffffff;
position: fixed;
bottom: 0;
width: 100%;
}
响应式设计
添加媒体查询适配移动设备:
@media (max-width: 600px) {
header h1 {
font-size: 24px;
}
main {
padding: 10px;
}
section {
padding: 15px;
}
}
交互效果增强
通过CSS悬停效果提升用户体验:
header {
transition: background 0.3s ease;
}
header:hover {
background: #e8491d;
}
ul li:hover {
color: #e8491d;
cursor: default;
}
进阶布局技巧
使用Flexbox或Grid优化布局:
/* Flexbox示例:技能列表横向排列 */
.skills ul {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.skills li {
background: #e8491d;
color: white;
padding: 5px 10px;
border-radius: 3px;
}
部署与扩展
- 将项目上传至GitHub Pages或Netlify免费托管
- 后续可扩展添加项目展示区、博客链接等模块
- 学习使用CSS变量(如
--primary-color: #e8491d;)统一主题色
通过以上步骤,逐步构建一个结构清晰、样式美观的静态个人主页,适合作为CSS入门练手项目。

被折叠的 条评论
为什么被折叠?



