3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

font-variant-numericで数値の表現方法を指定する

Last updated at Posted at 2023-07-18

font-variant-numericとは

font-variant-numericは、フォントの数字の表現方法を指定するCSSプロパティです。
caniuseによるとすべてのモダンブラウザで利用可能です。
このプロパティを使用することで、フォントの数字のスタイルを変更できます。
スクリーンショット 2023-07-18 14.40.46.png

font-variant-numericの使用方法

font-variant-numericは、normalordinalslashed-zerolining-numsoldstyle-numsproportional-numstabular-numsdiagonal-fractionsstacked-fractionsのいずれかの値を取ります。
例えば、以下のようにして使用します。

p {
  font-variant-numeric: lining-nums;
}

この例では、段落内の数字がlining-numsで定義された表示に変更されます。

font-variant-numericの各値について

デフォルトのフォントでは表現がわかりにくいので、サンプルはSource Sans Proを利用しました。

  • normal: フォントのデフォルトの数字表現

See the Pen Untitled by KokiSakano (@kokisakano) on CodePen.

  • ordinal: フォントが持つ序数の表現

See the Pen slashed-zero by KokiSakano (@kokisakano) on CodePen.

  • slashed-zero: 0の上に斜線(フォントによっては射線とは違う形で表現される)

See the Pen Untitled by KokiSakano (@kokisakano) on CodePen.

  • lining-nums: 高さが揃った数値
  • oldstyle-nums: 高さがバラバラな周りの小文字のアルファベットに馴染む数値

See the Pen lining-nums by KokiSakano (@kokisakano) on CodePen.

  • proportional-nums: 数字の幅がバラバラ
  • tabular-nums: 数字の幅が均等

See the Pen figure by KokiSakano (@kokisakano) on CodePen.

  • diagonal-fractions: 斜めで人まとまりの分数
  • stacked-fractions: 横に数値と射線を積み重ねた分数

See the Pen figure by KokiSakano (@kokisakano) on CodePen.

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?