设置页眉区域样式
本课属于 Coddy HTML 学习旅程的“精通 CSS”单元。第 26 课,共 43 课。
挑战
简单在这个迷你项目中,你将只用 CSS,让一个有趣的兴趣爱好落地页焕发生机。
HTML 已经帮你写好了。你的任务是一步步为它添加样式,就像真正的前端开发者一样。这是练习实际布局、按钮和样式技巧的好方法!
这是你最终要制作的页面预览:

在第一个挑战中,我们先为页面顶部添加样式,也就是页眉(也称为 "hero" 区域)。现在,它只是位于页面顶部的纯文本。你的目标是把它变成简洁醒目、能够介绍页面内容的区域。
你的 CSS 挑战:
- 移除默认间距:为
body设置margin: 0,并为它添加背景色。 - 为
.hero区域设置背景色(rgb(30, 207, 104))和 50px 的内边距。 - 在
.hero上使用 Flexbox,让所有内容居中:display: flexflex-direction: columnalign-items: centerjustify-content: centertext-align: center
- 使用
.hero h1和.hero p为文本添加样式。
确保顶部区域简洁醒目。
亲手试试
<html>
<head>
<title>Hobby Club Landing Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="hero">
<div class="container">
<h1>Welcome to Hobby Club</h1>
<p>Find your passion. Join a community. Grow your skills.</p>
<a href="#" class="btn">Get Started</a>
</div>
</header>
<section class="features">
<h2 class="section-title">Popular Clubs</h2>
<div class="cards">
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fa/Android_Emoji_1f4f7_red.svg" width="20px"></div>
<h3>Photography</h3>
<p>Capture the moment and share your perspective.</p>
</div>
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/5/51/Emoji_u1f3a8.svg" width="20px"></div>
<h3>Art & Design</h3>
<p>Draw, paint, and bring your creative ideas to life.</p>
</div>
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/e/e6/Emoji_u1f3ae.svg" width="20px"></div>
<h3>Gaming</h3>
<p>Connect with fellow gamers and play your favorite titles.</p>
</div>
</div>
</section>
</body>
</html>
精通 CSS中的所有课
自己练习: Web 在线编辑器