此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

CSSFontFaceRule:style 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

CSSFontFaceRule 接口的只读属性 style 返回 @font-face At 规则的样式信息。这些信息以 CSSStyleDeclaration 对象的形式提供。

CSSStyleDeclaration 对象。

示例

以下示例使用了 @font-face 页面中的示例 CSS。返回的第一个 CSSRule 将是一个 CSSFontFaceRulestyle 属性返回一个 CSSStyleDeclaration,其中包含 fontFamilyfontWeightsrc 属性,这些属性包含规则中的信息。

css
@font-face {
  font-family: MyHelvetica;
  src:
    local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
    url(MgOpenModernaBold.ttf);
  font-weight: bold;
}
js
const myRules = document.styleSheets[0].cssRules;
console.log(myRules[0].style); // CSSStyleDeclaration

规范

Specification
CSS Fonts Module Level 4
# dom-cssfontfacerule-style

浏览器兼容性