Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CSSNestedDeclarations

CSSNestedDeclarations

Baseline 2024
Newly available

Since ⁨December 2024⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

TheCSSNestedDeclarations interface of theCSS Rule API is used to group nestedCSSRules.

The interface allows theCSS Object Model (CSSOM to mirror the structure of CSS documents with nested CSS rules, and ensure that rules are parsed and evaluated in the order that they are declared.

Note:Implementations that do not support this interface may parse nested rules in the wrong order.SeeBrowser compatibility for more information.

CSSRule CSSNestedDeclarations

Instance properties

Inherits properties from its ancestorCSSRule.

CSSNestedDeclarations.styleRead only

Returns the values of the nested rules.

Instance methods

No specific methods; inherits methods from its ancestorCSSRule.

Examples

CSS

The CSS below includes a selector.foo that contains two declarations and a media query.

css
.foo {  background-color: silver;  @media screen {    color: tomato;  }  color: black;}

This is represented by a number of JavaScript objects in theCSS Object Model:

  • ACSSStyleRule object that represents thebackground-color: silver rule.This can be returned viadocument.styleSheets[0].cssRules[0].
  • ACSSMediaRule object that represents the@media screen rule, and which can be returned viadocument.styleSheets[0].cssRules[0].cssRules[0].
    • TheCSSMediaRule object contains aCSSNestedDeclaration object which represents thecolor: tomato rule nested by the@media screen rule.This can be returned viadocument.styleSheets[0].cssRules[0].cssRules[0].cssRules[0].
  • The final rule is aCSSNestedDeclaration object that represents thecolor: black rule in the stylesheet, and which can be returned viadocument.styleSheets[0].cssRules[0].cssRules[1].

Note:All top-level styles after the firstCSSNestedDeclaration must also be represented asCSSNestedDeclaration objects in order to follow theCSS nested declarations rule

CSSOM (CSS Object Model)

↳ CSSStyleRule  .style    - background-color: silver  ↳ CSSMediaRule    ↳ CSSNestedDeclarations      .style (CSSStyleDeclaration, 1) =      - color: tomato  ↳ CSSNestedDeclarations    .style (CSSStyleDeclaration, 1) =      - color: black

Specifications

Specification
CSS Nesting Module
# cssnesteddeclarations

Browser compatibility

See Also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp