制作css页面
创建HTML文件结构
新建一个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>CSS页面示例</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>页面标题</h1>
</header>
<main>
<section class="content">
<p>这里是主要内容区域</p>
</section>
</main>
<footer>
<p>页脚信息</p>
</footer>
</body>
</html>
编写基础CSS样式
新建styles.css文件,添加基础样式:

/* 全局样式 */
body {
font-family: 'Arial', sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
color: #333;
}
/* 头部样式 */
header {
background-color: #4CAF50;
color: white;
padding: 1rem;
text-align: center;
}
/* 主体内容样式 */
main {
padding: 2rem;
}
.content {
max-width: 800px;
margin: 0 auto;
padding: 1rem;
border: 1px solid #ddd;
border-radius: 5px;
}
/* 页脚样式 */
footer {
background-color: #333;
color: white;
text-align: center;
padding: 1rem;
position: fixed;
bottom: 0;
width: 100%;
}
添加响应式设计
在CSS文件中添加媒体查询,实现响应式布局:
@media (max-width: 600px) {
header h1 {
font-size: 1.5rem;
}
.content {
padding: 0.5rem;
}
main {
padding: 1rem;
}
}
引入CSS动画效果
添加简单的动画效果增强交互体验:

/* 悬停动画 */
.content:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
/* 加载动画 */
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
body {
animation: fadeIn 0.5s ease-in;
}
使用CSS变量管理主题色
通过CSS变量统一管理颜色方案:
:root {
--primary-color: #4CAF50;
--secondary-color: #333;
--text-color: #333;
--light-bg: #f9f9f9;
}
header {
background-color: var(--primary-color);
}
footer {
background-color: var(--secondary-color);
}
body {
color: var(--text-color);
background-color: var(--light-bg);
}
添加Flexbox布局示例
使用Flexbox创建导航栏:
<nav>
<ul class="nav-list">
<li><a href="#">首页</a></li>
<li><a href="#">产品</a></li>
<li><a href="#">关于</a></li>
<li><a href="#">联系</a></li>
</ul>
</nav>
.nav-list {
display: flex;
list-style: none;
padding: 0;
justify-content: center;
background-color: var(--primary-color);
}
.nav-list li {
margin: 0 1rem;
}
.nav-list a {
color: white;
text-decoration: none;
padding: 0.5rem;
}
.nav-list a:hover {
background-color: rgba(255,255,255,0.2);
border-radius: 4px;
}






