feat: Add CSS layout exercises and corresponding HTML files

- Created multiple exercises under the CSS layout section, including:
  - Final page layout with CSS styles and HTML structure.
  - Display and flow concepts with examples of block, inline, and none display types.
  - Selectors and pseudo-classes with practical examples.
  - Overflow and sizing handling in CSS.
  - Grid layout basics for two-dimensional layouts.
  - Fixed and sticky positioning examples.
  - Centering techniques for common layout scenarios.

- Added README files for each exercise to outline objectives and file structures.
- Updated main README to include new sections and usage instructions.
This commit is contained in:
chali
2026-03-09 14:16:22 +08:00
commit 4495ae0e28
85 changed files with 2566 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# 练习 4定位与徽标
## 目标
理解 `position: relative``position: absolute` 的配合。
## 你要练什么
- `position: relative`
- `position: absolute`
- `top`
- `right`
- `z-index`
## 任务
请完成一个课程推荐卡片,要求:
- 卡片右上角有一个“热门”徽标
- 徽标固定贴在卡片角上
- 卡片主体仍保持正常排版
- 按钮和标题之间留出合理距离
## 文件
- [starter.html](/Volumes/Macintosh HD 1/home/front-end-example/02-css-layout/04-position-badge/starter.html)
- [starter.css](/Volumes/Macintosh HD 1/home/front-end-example/02-css-layout/04-position-badge/starter.css)
- [answer.html](/Volumes/Macintosh HD 1/home/front-end-example/02-css-layout/04-position-badge/answer.html)
- [answer.css](/Volumes/Macintosh HD 1/home/front-end-example/02-css-layout/04-position-badge/answer.css)

View File

@@ -0,0 +1,38 @@
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #fff7ed;
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}
.card {
position: relative;
width: 360px;
padding: 32px 24px 24px;
border-radius: 20px;
background: #ffffff;
border: 1px solid #fed7aa;
box-shadow: 0 18px 40px rgba(234, 88, 12, 0.12);
}
.badge {
position: absolute;
top: -10px;
right: 18px;
z-index: 1;
padding: 6px 12px;
border-radius: 999px;
background: #ea580c;
color: #ffffff;
font-size: 14px;
}
a {
display: inline-block;
margin-top: 18px;
color: #9a3412;
text-decoration: none;
font-weight: 700;
}

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>定位与徽标</title>
<link rel="stylesheet" href="./answer.css" />
</head>
<body>
<article class="card">
<span class="badge">热门</span>
<h1>CSS 布局专项课</h1>
<p>重点掌握盒模型、Flex、定位和常见页面排版方式。</p>
<a href="#">查看详情</a>
</article>
</body>
</html>

View File

@@ -0,0 +1,11 @@
body {
}
.card {
}
.badge {
}
a {
}

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>定位与徽标</title>
<link rel="stylesheet" href="./starter.css" />
</head>
<body>
<article class="card">
<span class="badge">热门</span>
<h1>CSS 布局专项课</h1>
<p>重点掌握盒模型、Flex、定位和常见页面排版方式。</p>
<a href="#">查看详情</a>
</article>
</body>
</html>