Foundation 价格表
核对 Foundation 5 价格表 ul.pricing-table 的各语义行类名(.title/.price/.description/.bullet-item/.cta-button)样式与 .medium-4 响应式三栏网格实测表现。
学完这一章,你能够
- 核对 Foundation 5 价格表 ul.pricing-table 的各语义行类名(.title/.price/.description/.bullet-item/.cta-button)样式与 .medium-4 响应式三栏网格实测表现。
价格表组件结构与核心类名
Foundation 5 价格表(Pricing Tables)专为套餐对比与企业产品报价设计,通过无序列表 `<ul class="pricing-table">` 将标题、价格、简介、特性清单与行动按钮组织成垂直卡片。
价格表由以下 6 个语义角色构成:`ul.pricing-table` 定义外层容器;`li.title` 定义深色背景的产品标题;`li.price` 定义浅灰背景的大字号价格行;`li.description` 放置可选的产品摘要描述;多个 `li.bullet-item` 逐条列出套餐特性;底部行动按钮行在 Foundation 5 正式样式中的类名为 `li.cta-button`(部分旧文偶见笔误写作 `li.ca-button`,编码时应以 `li.cta-button` 为准),内嵌 `Buy`、`Sign Up` 等 `.button` 链接。价格表默认 `100%` 撑满父容器宽度,所有项均居中对齐并带边框分隔。本站离线 Chromium 在 `600px` 容器内实测:`ul.pricing-table` 精确占满 `100%` 宽度并具 `1px solid` 外框,`.title` 为深灰 `rgb(51, 51, 51)` 居中,`.price` 为浅灰 `rgb(246, 246, 246)` 且字号 `32px`,`.description` 与 3 项 `.bullet-item` 底部为 `dotted` 点状线且全部居中,`.cta-button` 居中包裹蓝色 `rgb(0, 140, 186)` 按钮。
多套餐价格表响应式网格
要并排展示多个产品档位(如 `Basic`、`Pro`、`Premium`),只需把各个 `<ul class="pricing-table">` 放进 Foundation 12 列网格中,例如使用 `<div class="row">` 包裹三个 `<div class="medium-4 columns">` 实现三等分宽度。本站离线实测:在 `960px` 桌面视口下三列位于同一行,每列精确等宽 `320px`(扣除左右各 `15px` 列内边距后内部价格表占满 `290px`);在 `480px` 窄屏视口下三列自动转为纵向堆叠,每列宽度撑满 `480px`。
离线验证 Foundation 5 价格表结构样式与 .medium-4 三栏响应式网格
"""Offline Playwright Chromium lab for Foundation 5 Ch 18 (pricing-tables)."""
import json
from playwright.sync_api import sync_playwright
FOUNDATION_PRICING_CSS = """
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; padding: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: #222; background: #fff; }
.row {
width: 100%;
max-width: 960px;
margin: 0 auto;
}
.row::before, .row::after { content: " "; display: table; }
.row::after { clear: both; }
.columns {
position: relative;
padding-left: 15px;
padding-right: 15px;
width: 100%;
float: left;
}
@media only screen and (min-width: 40.063em) {
.medium-4 { width: 33.33333%; }
}
.pricing-table {
border: solid 1px #DDDDDD;
margin: 0 0 1.25rem 0;
padding: 0;
list-style: none;
width: 100%;
}
.pricing-table .title {
background-color: #333333;
padding: 0.9375rem 1.25rem;
text-align: center;
color: #EEEEEE;
font-weight: normal;
font-size: 1rem;
}
.pricing-table .price {
background-color: #F6F6F6;
padding: 0.9375rem 1.25rem;
text-align: center;
color: #333333;
font-weight: normal;
font-size: 2rem;
}
.pricing-table .description {
background-color: #FFFFFF;
padding: 0.9375rem;
text-align: center;
color: #777777;
font-size: 0.75rem;
border-bottom: dotted 1px #DDDDDD;
}
.pricing-table .bullet-item {
background-color: #FFFFFF;
padding: 0.9375rem;
text-align: center;
color: #333333;
font-size: 0.875rem;
border-bottom: dotted 1px #DDDDDD;
}
.pricing-table .cta-button {
background-color: #FFFFFF;
text-align: center;
padding: 1.25rem 1.25rem 0;
}
.button {
display: inline-block;
background-color: #008CBA;
color: #FFFFFF;
padding: 0.75rem 1.5rem;
margin-bottom: 1.25rem;
text-decoration: none;
font-size: 1rem;
}
"""
HTML_PAGE = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="utf-8"><style>{FOUNDATION_PRICING_CSS}</style></head>
<body>
<div id="single-box" style="width: 600px; margin: 16px auto;">
<ul id="pt-single" class="pricing-table">
<li class="title">Basic</li>
<li class="price">$19.99</li>
<li class="description">Great for small business</li>
<li class="bullet-item">24/7 Support</li>
<li class="bullet-item">15GB Storage</li>
<li class="bullet-item">1GB Bandwidth</li>
<li class="cta-button"><a class="button" href="#">Buy</a></li>
</ul>
</div>
<div id="grid-row" class="row">
<div id="col-1" class="medium-4 columns">
<ul class="pricing-table">
<li class="title">Basic</li>
<li class="price">$19.99</li>
<li class="bullet-item">15GB Storage</li>
<li class="cta-button"><a class="button" href="#">Buy</a></li>
</ul>
</div>
<div id="col-2" class="medium-4 columns">
<ul class="pricing-table">
<li class="title">Pro</li>
<li class="price">$49.99</li>
<li class="bullet-item">50GB Storage</li>
<li class="cta-button"><a class="button" href="#">Buy</a></li>
</ul>
</div>
<div id="col-3" class="medium-4 columns">
<ul class="pricing-table">
<li class="title">Premium</li>
<li class="price">$99.99</li>
<li class="bullet-item">200GB Storage</li>
<li class="cta-button"><a class="button" href="#">Buy</a></li>
</ul>
</div>
</div>
</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": 960, "height": 900})
page.set_content(HTML_PAGE)
# Case 1: single_pricing_table_anatomy
act_1 = page.evaluate("""() => {
const box = document.getElementById('single-box');
const ul = document.getElementById('pt-single');
const title = getComputedStyle(ul.querySelector('.title'));
const price = getComputedStyle(ul.querySelector('.price'));
const desc = getComputedStyle(ul.querySelector('.description'));
const bullet = getComputedStyle(ul.querySelector('.bullet-item'));
const cta = getComputedStyle(ul.querySelector('.cta-button'));
const btn = getComputedStyle(ul.querySelector('.cta-button .button'));
return {
fills_container_100pct: Math.round(ul.getBoundingClientRect().width) === Math.round(box.getBoundingClientRect().width),
table_border: getComputedStyle(ul).borderTopWidth + ' ' + getComputedStyle(ul).borderTopStyle,
title_bg: title.backgroundColor,
title_align: title.textAlign,
price_bg: price.backgroundColor,
price_font_size: price.fontSize,
desc_border_bottom: desc.borderBottomStyle,
bullet_count: ul.querySelectorAll('.bullet-item').length,
bullet_align: bullet.textAlign,
cta_align: cta.textAlign,
cta_button_bg: btn.backgroundColor,
};
}""")
exp_1 = {
"fills_container_100pct": True,
"table_border": "1px solid",
"title_bg": "rgb(51, 51, 51)",
"title_align": "center",
"price_bg": "rgb(246, 246, 246)",
"price_font_size": "32px",
"desc_border_bottom": "dotted",
"bullet_count": 3,
"bullet_align": "center",
"cta_align": "center",
"cta_button_bg": "rgb(0, 140, 186)",
}
cases.append({
"name": "single_pricing_table_anatomy",
"expected": exp_1,
"actual": act_1,
"passed": act_1 == exp_1,
})
# Case 2: three_column_pricing_grid_desktop
act_2 = page.evaluate("""() => {
const cols = ['col-1', 'col-2', 'col-3'].map(id => document.getElementById(id).getBoundingClientRect());
const widths = cols.map(r => Math.round(r.width));
const sameRow = cols.every(r => Math.abs(r.top - cols[0].top) <= 1);
const tableWidth = Math.round(document.querySelector('#col-1 .pricing-table').getBoundingClientRect().width);
return {
same_row: sameRow,
col_widths: widths,
inner_table_width: tableWidth,
};
}""")
exp_2 = {
"same_row": True,
"col_widths": [320, 320, 320],
"inner_table_width": 290,
}
cases.append({
"name": "three_column_pricing_grid_desktop",
"expected": exp_2,
"actual": act_2,
"passed": act_2 == exp_2,
})
# Case 3: three_column_pricing_grid_mobile
page.set_viewport_size({"width": 480, "height": 900})
act_3 = page.evaluate("""() => {
const cols = ['col-1', 'col-2', 'col-3'].map(id => document.getElementById(id).getBoundingClientRect());
const widths = cols.map(r => Math.round(r.width));
const stacked = cols[1].top >= cols[0].bottom - 1 && cols[2].top >= cols[1].bottom - 1;
return {
stacked_vertically: stacked,
col_widths: widths,
};
}""")
exp_3 = {
"stacked_vertically": True,
"col_widths": [480, 480, 480],
}
cases.append({
"name": "three_column_pricing_grid_mobile",
"expected": exp_3,
"actual": act_3,
"passed": act_3 == exp_3,
})
browser.close()
print(json.dumps({"cases": cases}, ensure_ascii=False))
if __name__ == "__main__":
main()
- 在离线 Chromium 中核对 .pricing-table 100% 满宽、.title/.price/.description/.bullet-item/.cta-button 样式与 960px 三等宽并排 / 480px 纵向堆叠。
所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
当前源码 SHA256:4bfc834b95bd22580e08795cd4f912e4504404803c37e76f885fa2372ecb3d42
本地运行
解压后按 README 说明在对应本地环境运行脚本。
所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
ZIP SHA256:afd444a84672e0dbf5e3fab404c852b802827f9bd860b5e4a9e00e5f14376527
常见错误与边界
- 实际端口、文档资源与应用配置都应和测试条件一致。
练习与解答
在 Foundation 5 价格表中,底部购买按钮所在列表项的标准类名是什么?如何把 3 个套餐表在中等及以上屏幕等宽并排?
展开参考解答
标准类名为 li.cta-button(内部放置 <a class="button">);将 3 个 ul.pricing-table 分别放入 <div class="row"> 下的三个 <div class="medium-4 columns"> 中即可在 ≥641px 视口三等宽并排、小屏自动堆叠。