CSSFontFaceRule

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{APIRef("CSSOM")}}

The **CSSFontFaceRule** interface represents an {{cssxref("@font-face")}} at-rule.

{{InheritanceDiagram}}

Instance properties

_Inherits properties from its ancestor {{domxref("CSSRule")}}._

  • {{domxref("CSSFontFaceRule.style")}} {{ReadOnlyInline}}
  • : Returns a {{domxref("CSSFontFaceDescriptors")}} object that allows reading and setting the descriptors of the associated {{cssxref("@font-face")}} at-rule.

Instance methods

_Inherits methods from its ancestor {{domxref("CSSRule")}}._

Examples

Accessing @font-face properties

This example defines a {{cssxref("@font-face")}} rule and then iterates over the rules on the page until the associated CSSFontFaceRule is found. It then logs some of the properties.

CSS

css
@font-face {
  font-family: "MyHelvetica";
  src:
    local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
    url("MgOpenModernaBold.woff2");
  font-weight: bold;
}
css hidden
html hidden

JavaScript

js hidden
js
const myRules = document.getElementById("css-output").sheet.cssRules;
for (const rule of myRules) {
  if (rule instanceof CSSFontFaceRule) {
    log(`this: ${rule}`);
    log(` cssText: ${rule.cssText}`);
    log(` parentRule: ${rule.parentRule}`);
    log(` parentStyleSheet: ${rule.parentStyleSheet}`);
    log(` type: ${rule.type}`);
    log(` style: ${rule.style}`);
  }
}

Result

{{EmbedLiveSample("Accessing @font-face properties", "100%", "250px")}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}