Сложные таблицы: связывание headers и id
Работайте с таблицами с объединёнными и многоуровневыми заголовками.
«Сложные таблицы: связывание headers и id» — бесплатный урок Web Accessibility Academy на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Web Accessibility Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Web Accessibility Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
When scope Is Not Enough
Some tables span cells or stack multiple header levels. Simple scope cannot describe a cell governed by two or three headers at once.
Spanned Headers Break Scope
A header that uses colspan to cover several columns confuses the simple model. The browser can no longer guess which cells it owns.
<th colspan="2" scope="colgroup">Q1</th>The id and headers Pairing
For complex tables, give each th an id and point each td to its headers by id. This wires cells to headers explicitly, no guessing.
<th id="q1">Q1</th>Listing Multiple Header ids
A data cell can name several headers in its headers attribute, separated by spaces. The reader announces them all in the order you list.
<td headers="ada q1">92</td>A Worked Example
Give the row header and column header each an id, then reference both from the cell. Now the value is fully described across both axes.
<th id="ada" scope="row">Ada</th>
<td headers="ada q1">92</td>scope=colgroup and rowgroup
For grouped headers, scope can be colgroup or rowgroup. Use these when one header spans a band of columns or rows above the detail headers.
<th colspan="2" scope="colgroup">2024</th>Two Header Levels
A year header over month headers needs both levels described. With id and headers each cell can reference the year and the month together.
Keep ids Unique
Every id on the page must be unique. Duplicate header ids silently break the pairing, so a quick validator pass saves real pain later.
Order in headers Matters
List ids in the order you want them read, usually the broadest header first. The screen reader follows your order exactly when it announces.
<td headers="year2024 month-jan ada">92</td>Simplify Before You Complicate
Before reaching for id and headers, ask if you can split one giant table into smaller simple ones. A simpler structure is almost always more accessible.
Verify in a Screen Reader
The id and headers technique is powerful but easy to mistype. Always confirm a few cells read correctly with a real screen reader, not just by eye.
Quick Check
A data cell is governed by both a row header and a spanned column header.
Recap: Explicit Pairing for Hard Tables
When spans or stacked levels defeat scope, give headers an id and reference them from each cell with headers. Keep ids unique and verify by ear.
Часто задаваемые вопросы
Урок «Сложные таблицы: связывание headers и id» бесплатный?
Да — полный текст урока «Сложные таблицы: связывание headers и id» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Web Accessibility Academy, подпишись на CoddyKit PRO. Курс Web Accessibility Academy содержит 4 уроков всего.
Чему я научусь в уроке «Сложные таблицы: связывание headers и id»?
Работайте с таблицами с объединёнными и многоуровневыми заголовками. Ты практикуешь Web Accessibility Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Web Accessibility Academy?
Предыдущий опыт не требуется. Web Accessibility Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.
Сколько времени занимает урок «Сложные таблицы: связывание headers и id»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Web Accessibility Academy?
Да. Каждый урок Web Accessibility Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- th, scope и элемент caption
- Правильные заголовки строк и столбцов
- Сложные таблицы: связывание headers и id
- Таблицы для разметки — ловушка