制作个人网页css
创建基础结构
新建一个HTML文件(如index.html),包含基本结构:
<!DOCTYPE html>
<html>
<head>
<title>个人网页</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>你的名字</h1>
<nav>
<a href="#about">关于</a>
<a href="#projects">项目</a>
<a href="#contact">联系</a>
</nav>
</header>
<main>
<section id="about">
<h2>关于我</h2>
<p>个人简介内容...</p>
</section>
<section id="projects">
<h2>项目展示</h2>
<div class="project-grid"></div>
</section>
</main>
<footer id="contact">
<p>© 2023 你的名字</p>
</footer>
</body>
</html>
基础样式设置
创建styles.css文件,添加全局样式:

body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
color: #333;
}
header {
background: #2c3e50;
color: white;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a {
color: white;
margin-left: 1.5rem;
text-decoration: none;
}
section {
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
}
响应式设计
添加媒体查询适应不同设备:
@media (max-width: 768px) {
header {
flex-direction: column;
text-align: center;
}
nav {
margin-top: 1rem;
}
nav a {
display: block;
margin: 0.5rem 0;
}
}
项目展示布局
为项目部分添加网格布局:

.project-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1.5rem;
margin-top: 1rem;
}
.project-card {
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
transition: transform 0.3s ease;
}
.project-card:hover {
transform: translateY(-5px);
}
.project-card img {
width: 100%;
height: 200px;
object-fit: cover;
}
.project-info {
padding: 1rem;
}
交互效果
添加悬停和焦点状态:
nav a:hover {
opacity: 0.8;
}
button, input[type="submit"] {
background: #3498db;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
transition: background 0.3s ease;
}
button:hover {
background: #2980b9;
}
动画效果
为页面元素添加简单动画:
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
section {
animation: fadeIn 0.5s ease-in;
}
.project-card {
animation: fadeIn 0.5s ease-in forwards;
animation-delay: calc(var(--order) * 0.1s);
}






