Skip to content

简单 Landing Page

简单 约 25 分钟

你将构建什么

`landing.HTML` file 链接到 `landing.CSS` file. page 有 centered hero 块使用大 heading, one-行 subtitle, 样式 button, and footer 使用 copyright 行.

学习目标

  • 链接外部 CSS file 到 HTML document
  • Use CSS 到中心内容 and 设置字体大小
  • 样式 button-如 anchor 使用 padding, 颜色, and 边框-radius
  • 添加 footer 那个 sits at 底部的 内容

前置要求

  • HTML 结构 (head, 请求体, headings, paragraphs)
  • Familiarity 使用 CSS selectors and 少数属性 (颜色, 字体-大小, padding)

步骤

  1. 1

    编写 HTML 结构

    创建 landing.HTML 使用 hero 小节包含 h1, p subtitle, and button. 添加 footer below. 链接 stylesheet in head.

    代码
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>Simple Landing</title>
        <link rel="stylesheet" href="landing.css">
      </head>
      <body>
        <section class="hero">
          <h1>Build something small today</h1>
          <p>A 10-minute landing page for your first idea.</p>
          <a href="#" class="btn">Get started</a>
        </section>
        <footer>© 2026 My First Page</footer>
      </body>
    </html>

    预期结果

    page shows heading, subtitle, 链接, and footer 使用默认浏览器样式.

  2. 2

    Reset and 中心 hero

    创建 landing.CSS. Reset 请求体 margin, 设置字体 family, and use flexbox on 请求体到 中心 hero 小节两者都 horizontally and vertically. Flexbox 是 simplest 方式到 中心 in CSS.

    代码
    body {
      margin: 0;
      font-family: system-ui, sans-serif;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: #f8fafc;
    }

    预期结果

    hero 块是 现在 centered in viewport 使用 light gray background.

  3. 3

    样式 hero 文本

    添加 .hero 规则那个 centers 文本 and 添加 spacing. 然后样式 h1 and subtitle 使用清晰大小 hierarchy — heading 应该是 可见地 larger than subtitle.

    代码
    .hero { text-align: center; }
    .hero h1 { font-size: 2.5rem; color: #0f172a; }
    .hero p { font-size: 1.125rem; color: #475569; }

    预期结果

    heading 是大 and dark, subtitle 是 smaller and gray, 两者都 centered.

  4. 4

    制作 button look clickable

    样式 .btn as button: padding, solid background, white 文本, 否 underline, and rounded 角落. 添加 hover 状态那个 darkens background 所以它 feels interactive.

    代码
    .btn {
      display: inline-block;
      margin-top: 1.5rem;
      padding: 0.75rem 1.5rem;
      background: #2563eb;
      color: #fff;
      text-decoration: none;
      border-radius: 0.5rem;
    }
    .btn:hover { background: #1d4ed8; }

    预期结果

    链接现在 looks 如 blue button and darkens on hover.

  5. 5

    样式 footer

    添加 footer 规则使用小 文本, muted 颜色, and 顶部 margin 所以它 sits below hero 不使用 overlapping. footer 应该总是 feel distinct 从主要内容.

    代码
    footer {
      margin-top: 2rem;
      font-size: 0.875rem;
      color: #94a3b8;
    }

    预期结果

    小, gray copyright 行 appears below hero 块.

自己动手试试

你学到了什么

你链接 CSS 到 HTML, used flexbox 到中心内容, 构建 visual hierarchy 使用字体大小 and 颜色, and turned plain 链接到 button — 核心 ingredients 的每个 landing page.

相关资源

相关课程

  • CSS

    Flexbox centering used in hero 小节.

  • CSS

    类 selectors 如 .hero and .btn used 这里.

相关练习

相关工具

  • 颜色 Tool

    选取 and convert hex 颜色 used in 你的 button and 文本.

相关速查表

相关参考文档

相关错误

相关术语

  • CSS

    Cascading 样式 Sheets.

  • Selector

    CSS selector 模式.

  • HTML

    HyperText Markup Language.

相关术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

  • CSS

    Cascading 样式 Sheets.

  • Selector

    CSS selector 模式.

  • HTML

    HyperText Markup Language.

相关错误

用大白话解释常见错误——什么意思、为什么发生、如何修复。

← 返回主题