导航

v2.1.0
数据展示

价格

按价格的阅读习惯排版,显示商品或服务的费用。

本页内容

价格表示购买商品或服务所需的费用,按阅读习惯排版:金额用大号字,较小的货币符号与金额顶部对齐,计费单位与金额基线对齐,视觉上更弱。价格组件本身不带独立背景。可将它放在套餐的卡片中、商品旁边或发票底部。

价格

<div class="tray flex flex-wrap gap(4) max-w(480) mx-auto">  <div class="card card-flat grow(1) basis(200)">    <div class="card-header">      <h3 class="card-title">Starter</h3>      <p class="card-description">For one person and a few projects.</p>    </div>    <p class="price">      <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span>    </p>    <div class="card-footer"><button class="btn" type="button">Choose Starter</button></div>  </div>  <div class="card card-flat grow(1) basis(200)">    <div class="card-header">      <h3 class="card-title">Team</h3>      <p class="card-description">For a team that ships every day.</p>    </div>    <p class="price">      <s class="price-was"><span class="sr-only">Was</span>$39</s><span class="sr-only">now</span><span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span>    </p>    <div class="card-footer">      <button class="btn btn-primary" type="button">Choose Team</button>    </div>  </div></div>
<div className="tray flex flex-wrap gap(4) max-w(480) mx-auto">  <div className="card card-flat grow(1) basis(200)">    <div className="card-header">      <h3 className="card-title">Starter</h3>      <p className="card-description">For one person and a few projects.</p>    </div>    <p className="price">      <span className="price-currency">$</span><span className="price-amount">9</span><span className="price-period">per month</span>    </p>    <div className="card-footer"><button className="btn" type="button">Choose Starter</button></div>  </div>  <div className="card card-flat grow(1) basis(200)">    <div className="card-header">      <h3 className="card-title">Team</h3>      <p className="card-description">For a team that ships every day.</p>    </div>    <p className="price">      <s className="price-was"><span className="sr-only">Was</span>$39</s><span className="sr-only">now</span><span className="price-currency">$</span><span className="price-amount">29</span><span className="price-period">per month</span>    </p>    <div className="card-footer">      <button className="btn btn-primary" type="button">Choose Team</button>    </div>  </div></div>
<div class="tray flex flex-wrap gap(4) max-w(480) mx-auto">  <div class="card card-flat grow(1) basis(200)">    <div class="card-header">      <h3 class="card-title">Starter</h3>      <p class="card-description">For one person and a few projects.</p>    </div>    <p class="price">      <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span>    </p>    <div class="card-footer"><button class="btn" type="button">Choose Starter</button></div>  </div>  <div class="card card-flat grow(1) basis(200)">    <div class="card-header">      <h3 class="card-title">Team</h3>      <p class="card-description">For a team that ships every day.</p>    </div>    <p class="price">      <s class="price-was"><span class="sr-only">Was</span>$39</s><span class="sr-only">now</span><span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span>    </p>    <div class="card-footer">      <button class="btn btn-primary" type="button">Choose Team</button>    </div>  </div></div>
<template>  <div class="tray flex flex-wrap gap(4) max-w(480) mx-auto">    <div class="card card-flat grow(1) basis(200)">      <div class="card-header">        <h3 class="card-title">Starter</h3>        <p class="card-description">For one person and a few projects.</p>      </div>      <p class="price">        <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span>      </p>      <div class="card-footer"><button class="btn" type="button">Choose Starter</button></div>    </div>    <div class="card card-flat grow(1) basis(200)">      <div class="card-header">        <h3 class="card-title">Team</h3>        <p class="card-description">For a team that ships every day.</p>      </div>      <p class="price">        <s class="price-was"><span class="sr-only">Was</span>$39</s><span class="sr-only">now</span><span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span>      </p>      <div class="card-footer">        <button class="btn btn-primary" type="button">Choose Team</button>      </div>    </div>  </div></template>

#组成部分

  • price-amount 表示金额,使用紧凑排列的等宽数字。也可填写“免费”或“定制”等文字。
  • price-currency 是货币符号,字号不到金额数字的一半,顶部与金额数字对齐。这样既能看出它属于金额,又不会抢占视觉焦点。
  • price-period 表示计费单位,例如每月、每席位或每千次请求。它使用较小的字号和较淡的文字颜色,与金额基线对齐。请用完整文字书写,例如写“每月”,因为“/mo”会被读成“slash mo”。
  • price-was 表示已失效的价格。它放在当前金额之前,使用较淡的文字颜色并加上删除线。使用 <s> 标记旧价,表示这段文字已不再准确。

按阅读顺序书写各部分:原价、货币符号、金额、计费单位。如果货币符号按惯例跟在金额后面,就把 price-currency 放在 price-amount 后面。

#尺寸

默认金额字号为 36px。price-sm 为 24px,适用于列表行或小卡片。price-lg 为 56px,适用于以单个价格为重点的页面。各部分均以金额字号为基准,因此可用 --price-size 将整个价格等比缩放到 24px 和 56px 之间的任意尺寸。

尺寸

<p class="price price-sm">  <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span></p><p class="price">  <span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span></p><p class="price price-lg">  <span class="price-currency">€</span><span class="price-amount">1,240</span><span class="price-period">per seat</span></p>
<>  <p className="price price-sm">    <span className="price-currency">$</span><span className="price-amount">9</span><span className="price-period">per month</span>  </p>  <p className="price">    <span className="price-currency">$</span><span className="price-amount">29</span><span className="price-period">per month</span>  </p>  <p className="price price-lg">    <span className="price-currency">€</span><span className="price-amount">1,240</span><span className="price-period">per seat</span>  </p></>
<p class="price price-sm">  <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span></p><p class="price">  <span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span></p><p class="price price-lg">  <span class="price-currency">€</span><span class="price-amount">1,240</span><span class="price-period">per seat</span></p>
<template>  <p class="price price-sm">    <span class="price-currency">$</span><span class="price-amount">9</span><span class="price-period">per month</span>  </p>  <p class="price">    <span class="price-currency">$</span><span class="price-amount">29</span><span class="price-period">per month</span>  </p>  <p class="price price-lg">    <span class="price-currency">€</span><span class="price-amount">1,240</span><span class="price-period">per seat</span>  </p></template>

#价格与统计指标

价格表示需要权衡的费用。带有标签和变化量的数值,例如本月营收,适合用统计指标。如果金额只是众多单元格中的一项,就在表格中使用 table-numeric。

#无障碍

  • 各部分按书写顺序朗读,例如“美元、二十九、每月”。货币符号须保留为文本,不能用背景图片呈现。
  • 部分屏幕阅读器不会提示价格带有删除线。需要明确区分新旧价格时,可添加视觉上隐藏的文字,例如在旧价前加“原价”,在当前金额前加“现价”。
  • 在卡片中用文字明确标出推荐套餐,避免只靠金额字号传达推荐信息。

#类名

类名说明
price价格单行显示,36px 的数字采用等宽数字样式,排列紧凑
price-sm字号为 24px,默认字号为 36px。与 price 一同使用
price-lg字号为 56px,用于页面着重展示的唯一一项价格。默认字号为 36px。与 price 一同使用
price-amount显示金额或“免费”等文字
price-currency货币符号的字号不到数字的一半,并与数字顶部对齐。
price-period计价单位,如每月或每席位。使用低调的小字,与价格基线对齐。
price-was将已失效的价格放在当前金额前,弱化显示并加删除线

#自定义属性

属性默认值说明
--price-size2.25rem数字字号,其他部分随之缩放

#源码

@master/ui/components/price.css
/* * Price: what something costs, set the way a price is read. * The amount is large, in tabular figures with a tight fit. The currency mark is small and hangs from the * top of the figures, level with their cap height; the period is small and quiet on their baseline. A price * that no longer holds stands before the amount, struck through, on a <s>. * Everything is sized from the amount, so one size class or one font-size scales the whole price. */@layer components.ui {  .price {    --price-size: 2.25rem;    display: inline-flex;    align-items: baseline;    min-width: 0;    margin: 0;    color: var(--color-text-strong);    font: var(--font-weight-control) var(--price-size)/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    letter-spacing: -.03em;    white-space: nowrap;    &.price-sm {      --price-size: 1.5rem;    }    &.price-lg {      --price-size: 3.5rem;      letter-spacing: -.04em;    }  }  /* The figures. */  .price-amount {    font: inherit;  }  /* The currency mark: under half the size of the figures, its top level with theirs. */  .price-currency {    align-self: flex-start;    margin-block-start: .16em;    margin-inline-end: .14em;    color: var(--color-text-body);    font-size: .46em;    letter-spacing: 0;    line-height: 1;  }  /* Per what: a month, a seat, a thousand requests. */  .price-period {    margin-inline-start: .3em;    color: var(--color-text-muted);    font-weight: 400;    font-size: max(.8125rem, .36em);    letter-spacing: 0;  }  /* The price that no longer holds: quiet, struck, before the one that does. */  .price-was {    margin-inline-end: .5em;    color: var(--color-text-muted);    font-weight: 400;    font-size: .5em;    letter-spacing: -.01em;    text-decoration-line: line-through;    /* The strike grows with the figures it crosses. */    text-decoration-thickness: max(1px, .07em);    text-decoration-color: var(--color-line-mark);  }}