dominant-baseline
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.
dominant-baseline は CSS のプロパティで、ボックス内のテキストとインラインレベルのコンテンツを整列させるために使用される特定のベースライン(主要ベースライン)を指定します。また、ボックスの整列コンテキストでベースライン揃えに参加するすべてのボックスの既定の整列ベースラインも示します。存在する場合、シェイプの dominant-baseline 属性を上書きします。
ベースラインはフォントベースライン表から選択されます。指定のフォントにベースライン表がない場合、またはベースライン表に希望するベースラインの項目がない場合、ブラウザーは経験則を使用して希望するベースラインの位置を決定することがあります。
dominant-baseline プロパティは、変倍ベースライン表を決定または再決定するために使用します。変倍ベースライン表は、 3 つの部分からなる複合値です。
- この主要ベースラインのベースライン識別子
- ベースライン表
- ベースライン表のフォントサイズ
dominant-baseline の値によっては、 3 つの値すべてを再決定します。他のものは、ベースライン表のフォントサイズのみを再設定します。初期値の auto が望ましくない結果をもたらす場合、このプロパティを使用して、望ましい変倍ベースライン表を明示的に設定することができます。
メモ:
dominant-baseline プロパティは、 SVG の <text>、<textPath>、<tspan> の各要素のみに効果があります。
構文
/* 初期値 */
dominant-baseline: auto;
/* キーワード値 */
dominant-baseline: alphabetic;
dominant-baseline: central;
dominant-baseline: hanging;
dominant-baseline: ideographic;
dominant-baseline: mathematical;
dominant-baseline: middle;
dominant-baseline: text-bottom;
dominant-baseline: text-top;
/* グローバル値 */
dominant-baseline: inherit;
dominant-baseline: initial;
dominant-baseline: revert;
dominant-baseline: revert-layer;
dominant-baseline: unset;
値
auto-
このプロパティが
<text>要素に適用された場合、計算された値はwriting-mode属性の値に依存します。writing-modeが横書きの場合、dominant-baseline成分の値はalphabeticです。 そうではなく、writing-modeが縦書きの場合、dominant-baseline成分の値はcentralです。このプロパティが
<tspan>、<textPath>のいずれかの要素に適用された場合、 dominant-baseline と baseline-table 成分は親テキストコンテンツ要素のものと同一のままとなります。baseline-shiftの計算値が実際にベースラインを移動させた場合、ベースライン表のフォントサイズ成分はdominant-baseline属性が存在する要素のfont-size属性の値に設定されます。それ以外の場合はベースライン表のフォントサイズは要素のものと同じままです。親のテキストコンテンツ要素がない場合、 scaled-baseline-table の値は
<text>要素であるかのように構築されます。 alphabetic-
dominant-baseline のベースライン識別子は
alphabeticに設定され、派生したベースライン表はフォント内のalphabeticのベースライン表を使用して構築され、ベースライン表のフォントサイズは、要素の SVG 属性であるfont-sizeの値、または設定されている場合は CSS のfont-sizeの値に変更されます。 central-
主要ベースラインのベースライン識別子は
centralに設定されます。派生ベースラインテーブルは、フォントのベースラインテーブルで定義されたベースラインから構築されます。フォントのベースラインテーブルは、ベースラインテーブル名のideographic、alphabetic、hanging、mathematicalの優先順位で選択されます。ベースラインテーブルのフォントサイズは、要素の SVG 属性font-sizeの値、または設定されている場合は CSS のfont-sizeプロパティの値に変更されます。 hanging-
主要ベースラインのベースライン識別子を
hangingに設定し、派生ベースライン表をそのフォントのhangingベースライン表を用いて構築し、ベースライン表のフォントサイズを、この要素の SVG 属性font-sizeの値、または設定されている場合は CSS のfont-sizeプロパティの値に変更されます。 ideographic-
主要ベースラインのベースライン識別子を
ideographicに設定し、派生ベースライン表をそのフォントのideographicベースライン表を用いて構築し、ベースライン表のフォントサイズを、この要素の SVG 属性font-sizeの値、または設定されている場合は CSS のfont-sizeプロパティの値に変更されます。 mathematical-
主要ベースラインのベースライン識別子を
mathematicalに設定し、派生ベースライン表をそのフォントのmathematicalベースライン表を用いて構築し、ベースライン表のフォントサイズを、この要素の SVG 属性font-sizeの値、または設定されている場合は CSS のfont-sizeプロパティの値に変更されます。 middle-
主要ベースラインのベースライン識別子は
middleに設定されます。派生ベースラインテーブルは、フォントのベースラインテーブルで定義されたベースラインから構築されます。フォントのベースラインテーブルは、ベースラインテーブル名のideographic、alphabetic、hanging、mathematicalの優先順位で選択されます。ベースラインテーブルのフォントサイズは、要素の SVG 属性font-sizeの値、または設定されている場合は CSS のfont-sizeプロパティの値に変更されます。 text-bottom-
line-under の辺がベースラインとして使用されます。これはふつう、フォントの em ボックスの下辺です。
text-top-
line-over の辺がベースラインとして使用されます。これはふつう、フォントの em ボックスの上辺です。
公式定義
| 初期値 | auto |
|---|---|
| 適用対象 | Block-containers, flex containers, grid containers, inline boxes, table rows, and SVG text content elements |
| 継承 | あり |
| 計算値 | 指定通り |
| アニメーションの種類 | 離散値 |
形式文法
dominant-baseline =
auto |
text-bottom |
alphabetic |
ideographic |
middle |
central |
mathematical |
hanging |
text-top
例
<svg viewBox="0 0 450 160" width="700" height="200">
<text x="50" y="20">alphabetic</text>
<text x="50" y="60">central</text>
<text x="50" y="100">hanging</text>
<text x="50" y="140">ideographic</text>
<text x="250" y="20">mathematical</text>
<text x="250" y="60">middle</text>
<text x="250" y="100">text-bottom</text>
<text x="250" y="140">text-top</text>
<path
d="M 0,20 l 400,0
m -400,40 l 400,0
m -400,40 l 400,0
m -400,40 l 400,0"
stroke="grey" />
<text x="0" y="20" fill="red">auto</text>
<text x="0" y="60" fill="red">auto</text>
<text x="0" y="100" fill="red">auto</text>
<text x="0" y="140" fill="red">auto</text>
</svg>
text {
font-size: 20px;
}
text:nth-of-type(1) {
dominant-baseline: alphabetic;
}
text:nth-of-type(2) {
dominant-baseline: central;
}
text:nth-of-type(3) {
dominant-baseline: hanging;
}
text:nth-of-type(4) {
dominant-baseline: ideographic;
}
text:nth-of-type(5) {
dominant-baseline: mathematical;
}
text:nth-of-type(6) {
dominant-baseline: middle;
}
text:nth-of-type(7) {
dominant-baseline: text-bottom;
}
text:nth-of-type(8) {
dominant-baseline: text-top;
}
仕様書
| Specification |
|---|
| CSS Inline Layout Module Level 3> # dominant-baseline-property> |
| Scalable Vector Graphics (SVG) 2> # DominantBaselineProperty> |
ブラウザーの互換性
Loading…