<mfrac>

Baseline 2023
Newly available

Since January 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

<mfrac> MathML 元素用于显示分数。它还可以用于标记类似分数的对象,例如二项式系数勒让德符号

语法

html
<mfrac>numerator denominator</mfrac>

属性

这个元素的属性包括全局 MathML 属性以及以下属性:

denomalign 已弃用 非标准

分数下的分母对齐方式。可能的值包括:leftcenter(默认)和 right

linethickness

指示水平分数线的粗细的 <length-percentage>

numalign 已弃用 非标准

分数上的分子对齐方式。可能的值包括:leftcenter(默认)和 right

备注: 对于 linethickness 属性,一些浏览器可能还接受不推荐使用的值 mediumthinthick(其确切解释留给实现者)或旧版 MathML 长度

示例

简单分数

以下 MathML 代码应该渲染为分子是“a + 2”,分母是“3 − b”的分数:

html
<math display="block">
  <mfrac>
    <mrow>
      <mi>a</mi>
      <mo>+</mo>
      <mn>2</mn>
    </mrow>
    <mrow>
      <mn>3</mn>
      <mo></mo>
      <mi>b</mi>
    </mrow>
  </mfrac>
</math>

无分数线的分数

以下 MathML 代码应该渲染为二项式系数

html
<math display="block">
  <mrow>
    <mo>(</mo>
    <mfrac linethickness="0">
      <mi>n</mi>
      <mi>k</mi>
    </mfrac>
    <mo>)</mo>
  </mrow>
</math>

规范

Specification
MathML Core
# fractions-mfrac

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
mfrac
denomalign
DeprecatedNon-standard
linethickness
Named spaces (e.g. thinmathspace to mean 3/18em)
DeprecatedNon-standard
Nonzero unitless values (e.g. 5 to mean 500% the default thickness)
DeprecatedNon-standard
thin, medium, thick values
DeprecatedNon-standard
numalign
DeprecatedNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
Has more compatibility info.