跳到正文
Skillpedia
网站与界面(前端)75k · #2925

listitem

它能做什么

这项技能找出放在列表之外的列表项,例如放在 div 或 span 中的列表项,并加以修复。适用于希望列表有效且无障碍的网页制作者和模板作者。

适用场景

  • ✓当你请智能体检查页面或模板中列表项标记的时候。
  • ✓当组件把列表标记拆分到多个部分,而你怀疑某些列表项没有父级列表的时候。
  • ✓当你审查自定义 ARIA 列表,并想确认列表项角色位于列表角色之内的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/listitem/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/listitem/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我检查网站上是否有列表项缺少外层列表容器。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会检查每个列表项的父元素是否为 ul、ol 或 menu。如果不是,它会把这些项目包裹在正确的列表容器中。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Place list items within list containers

When a <li> element exists outside a list container, screen readers lose the ability to announce critical context: NVDA and JAWS will not say 'list of 5 items' or 'item 2 of 5' because there is no list context. VoiceOver may announce the orphan <li> as plain text without any group context, stripping users of the structural information that helps them understand how many items exist and where they are in the list.

Quick Reference

  • Every <li> element must have a direct parent of <ul>, <ol>, or <menu>
  • Orphan <li> elements are invalid HTML per the HTML Living Standard
  • Screen readers announce list type and item count (e.g., 'list, 3 items') only when <li> is inside a valid list container
  • Similarly, role='listitem' must be owned by a role='list' element per WAI-ARIA requirements

Check

Find all <li> elements in the DOM. For each, check that its direct parent element is <ul>, <ol>, or <menu>. Flag any <li> whose parent is <div>, <section>, <nav>, <span>, or any element other than those three. Also check role='listitem' elements to ensure their closest ancestor with a list-related role is role='list'.

Fix

For each orphan <li>: (1) Wrap it and any sibling <li> elements in the appropriate list container — use <ul> for unordered items or <ol> for sequentially ordered items. (2) If the <li> was being used purely for styling (e.g., a bullet point visual), replace it with a <div> or <p> and apply the visual style via CSS. (3) If inside a navigation element, ensure <nav><ul><li> nesting is maintained.

Explain

The HTML Living Standard specifies that <li> elements are only valid as children of <ul>, <ol>, or <menu>. This is a structural requirement, not a style preference. Screen readers use the list container to announce the list type ('bullet list' vs 'numbered list') and the total item count. Without the container, this context is lost entirely. Additionally, when list-style: none is applied to a <ul>, some browsers strip the list semantics — if this is intentional (e.g., a navigation menu), add role='list' to the <ul> to restore list semantics for screen readers.

Code Review

Review the rendered markup and interactive states that affect Place list items within list containers. Flag exact elements, roles, labels, focus behavior, or keyboard interactions that violate the rule, and note how to verify the fix with browser accessibility tooling or assistive tech.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/accessibility/listitem

常见问题

为什么列表项需要列表父元素?

没有父级列表,屏幕阅读器就无法告诉用户共有多少项,以及他们在列表中的位置。

哪些父元素是允许的?

这项技能把 ul、ol 和 menu 列为列表项的有效父元素。

自定义的 role 属性呢?

这项技能还会检查带有 listitem 角色的元素是否位于带有列表角色的元素之内。

详情

作者的原始描述

Use when applies to HTML documents with `<li>` elements. Also applies to custom ARIA lists where `role='listitem'` must be owned by `role='list'`. Common violations occur in templating systems where list markup is split across components or in CSS resets where developers use `<li>` for layout without proper list parents.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2925
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能