Foundation 列表
核对 Foundation 5 无序列表默认实心圆点、.circle 空心圆、.square 方块、.no-bullet 去标识、.inline-list 水平列表及基于 <ul> 的列表菜单实测排版。
学完这一章,你能够
- 核对 Foundation 5 无序列表默认实心圆点、.circle 空心圆、.square 方块、.no-bullet 去标识、.inline-list 水平列表及基于 <ul> 的列表菜单实测排版。
默认无序列表与项目符号变体
在 HTML 中无序列表由 `<ul>` 与若干 `<li>` 组成,用于纵向罗列并列条目(如连续 4 条 `List item`)。Foundation 5 默认保留实心圆点(`disc`)前缀与左侧缩进。本站离线 Chromium 实测默认 `<ul>` 的计算 `list-style-type` 为 `disc`,4 个列表项沿纵向严格递增排列。
Foundation 5 提供了三个直接作用于 `<ul>` 的符号修饰类:`.circle` 将前缀改为中空圆圈,`.square` 将前缀改为实心方块,`.no-bullet` 则彻底移除项目符号并消除左侧缩进。本站实测 `.circle` 计算 `list-style-type` 为 `circle`,`.square` 为 `square`,`.no-bullet` 为 `none` 且 `margin-left` 归零为 `0px`。
水平内联列表 .inline-list
当需要将列表项横向排成一行(例如页脚链接或简易筛选条)时,可在 `<ul>` 上添加 `.inline-list` 类。该类会移除项目符号并让子项 `<li>` 左浮动且保留统一左间距。本站离线实测 `.inline-list` 计算 `list-style-type` 为 `none`,子项 `float: left`、`margin-left: 22px`(`1.375rem`),4 个列表项处于同一水平行且横坐标严格从左向右递增。
无序列表菜单结构
Web 页面中的导航菜单在语义上通常以无序列表 `<ul>` 承载,每个 `<li>` 内部放置 `<a>` 链接(例如 `Home`、`Menu 1`、`Menu 2`、`Menu 3`)。未加导航组件类时,浏览器按默认无序列表将 4 个菜单链接垂直排列并带实心圆点;实际项目中可在此语义骨架上进一步叠加 `.inline-list`、`.side-nav` 或 `.tabs` 等 Foundation 导航类。本站离线实测确认 4 项链接文本完整且呈纵向堆叠(`list-style-type: disc`)。
离线验证 Foundation 5 默认/圆圈/方块/无符号列表、.inline-list 横向布局与列表菜单
展开查看收起
"""Offline Playwright Chromium lab for Foundation 5 Ch 15 (lists)."""
import json
from playwright.sync_api import sync_playwright
FOUNDATION_LISTS_CSS = """
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; padding: 20px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: #222; background: #fff; }
ul {
font-size: 1rem;
line-height: 1.6;
margin-bottom: 1.25rem;
margin-left: 1.1rem;
padding-left: 0;
list-style-position: outside;
list-style-type: disc;
}
ul.disc { list-style-type: disc; }
ul.circle { list-style-type: circle; }
ul.square { list-style-type: square; }
ul.no-bullet { list-style-type: none; margin-left: 0; }
.inline-list {
margin: 0 auto 1.0625rem auto;
margin-left: -1.375rem;
margin-right: 0;
padding: 0;
list-style: none;
overflow: hidden;
}
.inline-list > li {
list-style: none;
float: left;
margin-left: 1.375rem;
display: block;
}
.inline-list > li > * {
display: block;
}
"""
HTML_PAGE = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="utf-8"><style>{FOUNDATION_LISTS_CSS}</style></head>
<body>
<ul id="ul-default">
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
</ul>
<ul id="ul-circle" class="circle">
<li>Circle 1</li>
<li>Circle 2</li>
</ul>
<ul id="ul-square" class="square">
<li>Square 1</li>
<li>Square 2</li>
</ul>
<ul id="ul-nobullet" class="no-bullet">
<li>Plain 1</li>
<li>Plain 2</li>
</ul>
<ul id="ul-inline" class="inline-list">
<li><a href="#">Inline 1</a></li>
<li><a href="#">Inline 2</a></li>
<li><a href="#">Inline 3</a></li>
<li><a href="#">Inline 4</a></li>
</ul>
<ul id="ul-menu">
<li><a href="#home">Home</a></li>
<li><a href="#m1">Menu 1</a></li>
<li><a href="#m2">Menu 2</a></li>
<li><a href="#m3">Menu 3</a></li>
</ul>
</body>
</html>
"""
def launch_browser(p):
try:
return p.chromium.launch(headless=True)
except Exception:
return p.chromium.launch(headless=True, channel="chrome")
def main():
cases = []
with sync_playwright() as p:
browser = launch_browser(p)
page = browser.new_page(viewport={"width": 900, "height": 800})
page.set_content(HTML_PAGE)
# Case 1: default_and_disc_list
act_1 = page.evaluate("""() => {
const ul = document.getElementById('ul-default');
const s = getComputedStyle(ul);
const tops = Array.from(ul.children).map(li => Math.round(li.getBoundingClientRect().top));
const strictlyDown = tops.every((v, i) => i === 0 || v > tops[i - 1]);
return {
list_style_type: s.listStyleType,
item_count: ul.children.length,
vertical_stack: strictlyDown,
};
}""")
exp_1 = {
"list_style_type": "disc",
"item_count": 4,
"vertical_stack": True,
}
cases.append({
"name": "default_and_disc_list",
"expected": exp_1,
"actual": act_1,
"passed": act_1 == exp_1,
})
# Case 2: bullet_style_variants
act_2 = page.evaluate("""() => ({
circle_type: getComputedStyle(document.getElementById('ul-circle')).listStyleType,
square_type: getComputedStyle(document.getElementById('ul-square')).listStyleType,
nobullet_type: getComputedStyle(document.getElementById('ul-nobullet')).listStyleType,
nobullet_margin_left: getComputedStyle(document.getElementById('ul-nobullet')).marginLeft,
})""")
exp_2 = {
"circle_type": "circle",
"square_type": "square",
"nobullet_type": "none",
"nobullet_margin_left": "0px",
}
cases.append({
"name": "bullet_style_variants",
"expected": exp_2,
"actual": act_2,
"passed": act_2 == exp_2,
})
# Case 3: inline_list_horizontal_layout
act_3 = page.evaluate("""() => {
const ul = document.getElementById('ul-inline');
const items = Array.from(ul.children);
const rects = items.map(li => li.getBoundingClientRect());
const sameRow = rects.every(r => Math.abs(r.top - rects[0].top) <= 1);
const strictlyRight = rects.every((r, i) => i === 0 || r.left > rects[i - 1].right);
return {
list_style_type: getComputedStyle(ul).listStyleType,
li_float: getComputedStyle(items[0]).float,
li_margin_left: getComputedStyle(items[0]).marginLeft,
same_row: sameRow,
strictly_left_to_right: strictlyRight,
};
}""")
exp_3 = {
"list_style_type": "none",
"li_float": "left",
"li_margin_left": "22px",
"same_row": True,
"strictly_left_to_right": True,
}
cases.append({
"name": "inline_list_horizontal_layout",
"expected": exp_3,
"actual": act_3,
"passed": act_3 == exp_3,
})
# Case 4: unordered_list_menu_links
act_4 = page.evaluate("""() => {
const ul = document.getElementById('ul-menu');
const links = Array.from(ul.querySelectorAll('li > a'));
const tops = links.map(a => Math.round(a.getBoundingClientRect().top));
return {
labels: links.map(a => a.textContent),
vertical_stack: tops.every((v, i) => i === 0 || v > tops[i - 1]),
list_style_type: getComputedStyle(ul).listStyleType,
};
}""")
exp_4 = {
"labels": ["Home", "Menu 1", "Menu 2", "Menu 3"],
"vertical_stack": True,
"list_style_type": "disc",
}
cases.append({
"name": "unordered_list_menu_links",
"expected": exp_4,
"actual": act_4,
"passed": act_4 == exp_4,
})
browser.close()
print(json.dumps({"cases": cases}, ensure_ascii=False))
if __name__ == "__main__":
main()
查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包
本地运行
解压后按 README 说明在对应本地环境运行脚本。
本章附件与实例包
常见错误与边界检查
- 实际端口、文档资源与应用配置都应和测试条件一致。
技术规范与官方资料
练习与参考解答
查看参考解答
.no-bullet 仅去掉前缀圆点与左缩进,列表项仍保持垂直堆叠;.inline-list 在去除前缀的同时将各 <li> 左浮动排列在同一水平行上并保持 1.375rem 水平间距。