--- title: font-variant-numeric slug: Web/CSS/font-variant-numeric translation_of: Web/CSS/font-variant-numeric ---
{{CSSRef}}

font-variant-numeric CSS 属性控制数字,分数和序号标记的替代字形的使用。

{{EmbedInteractiveExample("pages/css/font-variant-numeric.html")}}

语法

font-variant-numeric: normal;
font-variant-numeric: ordinal;
font-variant-numeric: slashed-zero;
font-variant-numeric: lining-nums;         /* <numeric-figure-values> */
font-variant-numeric: oldstyle-nums;       /* <numeric-figure-values> */
font-variant-numeric: proportional-nums;   /* <numeric-spacing-values> */
font-variant-numeric: tabular-nums;        /* <numeric-spacing-values> */
font-variant-numeric: diagonal-fractions;  /* <numeric-fraction-values> */
font-variant-numeric: stacked-fractions;   /* <numeric-fraction-values> */
font-variant-numeric: oldstyle-nums stacked-fractions;

/* Global values */
font-variant-numeric: inherit;
font-variant-numeric: initial;
font-variant-numeric: unset;

此属性以以下两种方式之一指定:

normal

下列特性均不启用。

ordinal
启用序数形式显示。对序号标记强制启用特殊字形,如英文中的 1st,2nd,3rd,4th ,意大利文中的 1a。等同于 OpenType 特性 ordn
slashed-zero
启用区分零显示。强制使用带有斜杠的 0;常用于区分 O 和 0。等同于 OpenType 特性 zero
<numeric-figure-values>
下列值用于控制数字样式,可用值如下:
<numeric-spacing-values>
下列值用于控制数字宽度,可用值如下:
<numeric-fraction-values>
下列值用于控制分数字形,可用值如下:

Formal definition

{{cssinfo}}

Formal syntax

{{csssyntax}}

示例

Setting ordinal numeric forms

HTML

<p class="ordinal">1st, 2nd, 3rd, 4th, 5th</p>

CSS

/*
This example uses the Source Sans Pro OpenType font, developed by Adobe
and used here under the terms of the SIL Open Font License, Version 1.1:
http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web
*/

@font-face {
  font-family: "Source Sans Pro";
  font-style: normal;
  font-weight: 400;
  src: url("https://mdn.mozillademos.org/files/15757/SourceSansPro-Regular.otf") format("opentype");
}

.ordinal {
  font-variant-numeric: ordinal;
  font-family: "Source Sans Pro";
}

Result

{{EmbedLiveSample('Setting_ordinal_numeric_forms')}}

规范

Specification Status Comment
{{SpecName('CSS3 Fonts', '#propdef-font-variant-numeric', 'font-variant-numeric')}} {{Spec2('CSS3 Fonts')}} Initial definition

浏览器兼容性

{{Compat("css.properties.font-variant-numeric")}}