Menu
Coddy logo textTech

Темизация типографики

Часть раздела Практический фронтенд путешествия по HTML на Coddy. Урок 15 из 35.

Typography — важная part theming и design. Вместо того чтобы повсюду прописывать font style, мы можем определить их как CSS variables и повторно использовать на всём сайте. Это сохраняет style consistent и упрощает их последующее изменение.

Вы можете определить переменные для:

  • Семейства шрифтов (например, --font-family-base, --font-family-heading)
  • Размеры шрифта (например, --font-size-base, --font-size-h1)
  • Высота строки
  • Межбуквенный интервал

Сначала определим наши переменные typography в элементе :root:

:root {
  --font-primary: 'Open Sans', sans-serif;
  --font-secondary: 'Roboto', sans-serif;
  --font-size-base: 16px;
  --line-height: 1.5;
  --heading-color: #333;
  --text-color: #555;
}

Теперь примените эти variables к элементам text:

body {
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-color);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-secondary);
  color: var(--heading-color);
}

Эта настройка creates единую систему typography, которую вы можете легко изменять, меняя значения переменных в одном месте.

challenge icon

Задание

Легко

Создай тему Typography для website blog с отдельными variables для headings и текста paragraphs. Твоя задача:

  1. Определи CSS variables для:
    • sizes шрифтов для headings (--h1-size и --h2-size)
    • color текста для paragraphs  (--text-color): выбери color, отличный от чистого чёрного, для лучшей читаемости
    • color текста для headings   ( --heading-color ): выбери color, который выделяется на фоне текста body
  2. Примени эти variables, чтобы задать style для:
    • текста body 
    • headings h1 и h2

Твой CSS должен создавать чёткую visual иерархию между headings и текстом paragraphs.

REQUIRED OUTPUT FORMAT: <translation> [Your translated content here] </translation>

Попробуйте сами

<!DOCTYPE html>
<html>
<head>
  <title>Typography Theming</title>
  <style>
    :root {
      /* Typography variables */
      --primary-font: "Georgia", serif;       /* for paragraphs */
      --secondary-font: "Arial", sans-serif; /* for headings */

    }

    body {
      font-family: var(--primary-font);
      color: #000000;
      line-height: 1.6;
      margin: 0;
      padding: 20px;
      background-color: #f9f9f9;
    }

    h1, h2 {
      font-family: var(--secondary-font);
      color: #000000;
      margin-bottom: 0.5em;
    }

    h1 {
      font-size: 16px;
    }

    h2 {
      font-size: 16px;
    }

    p {
      margin-bottom: 1.2em;
    }

    .blog-post {
      max-width: 700px;
      margin: 0 auto;
      background: #fff;
      padding: 2rem;
      border-radius: 10px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
  </style>
</head>
<body>
  <div class="blog-post">
    <h1>The Beauty of Typography in Web Design</h1>
    <p>Typography plays a crucial role in how users read and experience content online. A good choice of fonts and sizes can make a website more readable and enjoyable.</p>

    <h2>Why Typography Matters</h2>
    <p>Clear and consistent typography improves accessibility, creates a visual hierarchy, and gives your website a professional feel. Without it, even the best design can look unpolished.</p>

    <h2>Mobile-First Typography</h2>
    <p>Starting with smaller, readable text for mobile and scaling up for desktops ensures your content looks great on any device. This approach is part of mobile-first design and theming.</p>
  </div>
</body>
</html>
quiz iconПроверьте себя

В этом уроке есть небольшой тест. Начните урок, чтобы ответить на вопросы и сохранить прогресс.

Все уроки раздела Практический фронтенд

Потренируйтесь самостоятельно: Песочница Web