制作css页面
CSS页面制作指南
基本结构
HTML文件需链接CSS文件,通常在<head>部分添加:
<link rel="stylesheet" href="styles.css">
布局设计
使用Flexbox实现响应式布局:
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
Grid布局适合复杂结构:
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
样式定制
文本样式示例:
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
color: #333;
}
按钮交互效果:
.button {
background-color: #4CAF50;
padding: 12px 24px;
border-radius: 4px;
transition: background-color 0.3s;
}
.button:hover {
background-color: #45a049;
}
响应式设计
媒体查询适配不同设备:
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.grid-container {
grid-template-columns: 1fr;
}
}
动画效果
CSS动画示例:
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.element {
animation: fadeIn 1s ease-in;
}
最佳实践
- 使用CSS变量维护主题色:
:root { --primary-color: #3498db; } .header { background-color: var(--primary-color); } - 采用BEM命名规范:
.nav__item--active { font-weight: bold; }







