init
This commit is contained in:
11
css3/01-responsive-dashboards/RADEME.md
Normal file
11
css3/01-responsive-dashboards/RADEME.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Responsive Dashboards
|
||||
|
||||
综合布局挑战:响应式仪表盘
|
||||
|
||||
题目要求:
|
||||
创建一个企业级数据仪表盘,要求:
|
||||
1. 使用Grid+Flex混合布局
|
||||
2. 实现深色/浅色主题切换
|
||||
3. 添加微交互动画效果
|
||||
4. 完全响应式设计
|
||||
5. 使用CSS变量和计算函数
|
||||
408
css3/01-responsive-dashboards/index.html
Normal file
408
css3/01-responsive-dashboards/index.html
Normal file
@@ -0,0 +1,408 @@
|
||||
<!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>
|
||||
<style>
|
||||
/* 在这里实现您的解决方案 */
|
||||
:root {
|
||||
--primary-color: #2563eb;
|
||||
--secondary-color: #64748b;
|
||||
--success-color: #10b981;
|
||||
--warning-color: #f59e0b;
|
||||
--danger-color: #ef4444;
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f8fafc;
|
||||
--text-primary: #1e293b;
|
||||
--text-secondary: #64748b;
|
||||
--border-color: #e2e8f0;
|
||||
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
||||
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--bg-primary: #1e293b;
|
||||
--bg-secondary: #334155;
|
||||
--text-primary: #f1f5f9;
|
||||
--text-secondary: #94a3b8;
|
||||
--border-color: #475569;
|
||||
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Inter", system-ui, sans-serif;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--bg-secondary) 0%,
|
||||
var(--bg-primary) 100%
|
||||
);
|
||||
min-height: 100vh;
|
||||
color: var(--text-primary);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.dashboard {
|
||||
display: grid;
|
||||
grid-template-columns: 280px 1fr;
|
||||
grid-template-rows: 80px 1fr;
|
||||
grid-template-areas:
|
||||
"sidebar header"
|
||||
"sidebar main";
|
||||
min-height: 100vh;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
/* 挑战1:实现侧边栏导航 */
|
||||
.sidebar {
|
||||
grid-area: sidebar;
|
||||
background: var(--bg-primary);
|
||||
border-right: 1px solid var(--border-color);
|
||||
padding: 2rem 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
box-shadow: var(--shadow);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
/* 挑战2:实现顶部导航栏 */
|
||||
.header {
|
||||
grid-area: header;
|
||||
background: var(--bg-primary);
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
padding: 0 2rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: var(--shadow);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
/* 挑战3:实现主内容区网格布局 */
|
||||
.main {
|
||||
grid-area: main;
|
||||
padding: 2rem;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 2rem;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
/* 挑战4:实现数据卡片组件 */
|
||||
.card {
|
||||
background: var(--bg-primary);
|
||||
border-radius: 16px;
|
||||
padding: 1.5rem;
|
||||
border: 1px solid var(--border-color);
|
||||
box-shadow: var(--shadow);
|
||||
transition: var(--transition);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--primary-color),
|
||||
var(--success-color)
|
||||
);
|
||||
opacity: 0;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.card:hover::before {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* 挑战5:实现统计图表占位 */
|
||||
.chart-container {
|
||||
height: 200px;
|
||||
background: linear-gradient(
|
||||
45deg,
|
||||
var(--bg-secondary) 25%,
|
||||
transparent 25%,
|
||||
transparent 75%,
|
||||
var(--bg-secondary) 75%
|
||||
)
|
||||
0 0/20px 20px;
|
||||
border-radius: 12px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chart-container::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(255, 255, 255, 0.1),
|
||||
transparent
|
||||
);
|
||||
animation: shimmer 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
/* 挑战6:实现主题切换按钮 */
|
||||
.theme-toggle {
|
||||
width: 48px;
|
||||
height: 24px;
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 12px;
|
||||
padding: 2px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
border: 1px solid var(--border-color);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.theme-toggle::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
background: var(--primary-color);
|
||||
border-radius: 50%;
|
||||
transition: var(--transition);
|
||||
left: 2px;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .theme-toggle::before {
|
||||
left: calc(100% - 22px);
|
||||
}
|
||||
|
||||
/* 挑战7:实现响应式设计 */
|
||||
@media (max-width: 1024px) {
|
||||
.dashboard {
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-areas:
|
||||
"header"
|
||||
"main";
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: -100%;
|
||||
top: 80px;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
transition: left 0.3s ease;
|
||||
}
|
||||
|
||||
.sidebar.active {
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* 挑战8:实现加载动画 */
|
||||
.loading {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-top: 2px solid var(--primary-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 挑战9:实现表格样式 */
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--bg-primary);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.data-table th,
|
||||
.data-table td {
|
||||
padding: 1rem;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
background: var(--bg-secondary);
|
||||
font-weight: 600;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.data-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.data-table tr:hover {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
/* 挑战10:实现自定义滚动条 */
|
||||
.scroll-container {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) var(--bg-secondary);
|
||||
}
|
||||
|
||||
.scroll-container::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.scroll-container::-webkit-scrollbar-track {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.scroll-container::-webkit-scrollbar-thumb {
|
||||
background: var(--primary-color);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.scroll-container::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--secondary-color);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dashboard">
|
||||
<aside class="sidebar">
|
||||
<div class="logo">📊 Dashboard</div>
|
||||
<nav class="nav">
|
||||
<a href="#" class="nav-item active">🏠 概览</a>
|
||||
<a href="#" class="nav-item">📈 分析</a>
|
||||
<a href="#" class="nav-item">👥 用户</a>
|
||||
<a href="#" class="nav-item">⚙️ 设置</a>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<header class="header">
|
||||
<h1>数据仪表盘</h1>
|
||||
<div class="header-actions">
|
||||
<button
|
||||
class="theme-toggle"
|
||||
onclick="toggleTheme()"
|
||||
></button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="main">
|
||||
<div class="card">
|
||||
<h3>用户总数</h3>
|
||||
<div class="stat">12,458</div>
|
||||
<div class="chart-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>收入</h3>
|
||||
<div class="stat">¥245,789</div>
|
||||
<div class="chart-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3>转化率</h3>
|
||||
<div class="stat">24.5%</div>
|
||||
<div class="chart-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="grid-column: span 2">
|
||||
<h3>最近活动</h3>
|
||||
<div
|
||||
class="scroll-container"
|
||||
style="max-height: 300px; overflow-y: auto"
|
||||
>
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户</th>
|
||||
<th>操作</th>
|
||||
<th>时间</th>
|
||||
<th>状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>张三</td>
|
||||
<td>购买产品</td>
|
||||
<td>2分钟前</td>
|
||||
<td>成功</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>李四</td>
|
||||
<td>提交表单</td>
|
||||
<td>5分钟前</td>
|
||||
<td>待处理</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>王五</td>
|
||||
<td>注册账号</td>
|
||||
<td>10分钟前</td>
|
||||
<td>成功</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleTheme() {
|
||||
const body = document.body;
|
||||
const currentTheme = body.getAttribute("data-theme");
|
||||
const newTheme = currentTheme === "dark" ? "light" : "dark";
|
||||
body.setAttribute("data-theme", newTheme);
|
||||
localStorage.setItem("theme", newTheme);
|
||||
}
|
||||
|
||||
// 初始化主题
|
||||
const savedTheme = localStorage.getItem("theme") || "light";
|
||||
document.body.setAttribute("data-theme", savedTheme);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user