css怎么制作个人主页
设计布局结构
使用CSS的Flexbox或Grid布局创建响应式结构。Flexbox适合一维排列(如导航栏),Grid适合二维布局(如整体页面分区)。例如:
.container {
display: grid;
grid-template-columns: 1fr 3fr;
gap: 20px;
}
设置基础样式
定义全局样式确保一致性:
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
color: #333;
margin: 0;
padding: 0;
}
a {
text-decoration: none;
color: #0066cc;
}
创建导航栏
固定顶部导航栏示例:
.navbar {
position: fixed;
top: 0;
width: 100%;
background-color: #f8f9fa;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.nav-links {
display: flex;
justify-content: space-around;
padding: 1rem;
}
设计内容区域
主内容区与侧边栏布局:
.main-content {
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.05);
}
.sidebar {
background: #f5f7fa;
padding: 1.5rem;
}
添加交互效果
悬停和点击反馈:
.button {
transition: all 0.3s ease;
}
.button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.active {
border-bottom: 2px solid #0066cc;
}
实现响应式设计
媒体查询适配不同设备:
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
}
.nav-links {
flex-direction: column;
}
}
美化图文展示
图片和文字混合排版:
.avatar {
width: 150px;
height: 150px;
border-radius: 50%;
object-fit: cover;
border: 3px solid white;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.project-card {
transition: transform 0.3s;
}
.project-card:hover {
transform: scale(1.03);
}
添加页脚样式
底部固定样式设计:
footer {
text-align: center;
padding: 2rem;
background: #2c3e50;
color: white;
margin-top: 2rem;
}
.social-icons {
display: flex;
justify-content: center;
gap: 15px;
}






