CssRule Class

https://drafts.csswg.org/cssom/#the-cssrule-interface

public abstract class CssRule

Properties

NameDescription
CssTexthttps://drafts.csswg.org/cssom/#dom-cssrule-csstext: the getter serializes the rule; the setter does nothing.
ParentRuleGets the rule that contains this rule, or null when the rule is at the top level of a style sheet.
ParentStyleSheetGets the style sheet that contains the rule, or null when the rule is not in a style sheet.
Typehttps://drafts.csswg.org/cssom/#dom-cssrule-type: 0 for the rule types that have no legacy type.

https://drafts.csswg.org/cssom/#dom-cssrule-csstext: the getter serializes the rule; the setter does nothing.

public string CssText { get; set; }

ParentRule

CSSRules.cs

Gets the rule that contains this rule, or null when the rule is at the top level of a style sheet.

public CssRule? ParentRule { get; }

ParentStyleSheet

CSSRules.cs

Gets the style sheet that contains the rule, or null when the rule is not in a style sheet.

public CssStyleSheet? ParentStyleSheet { get; }

https://drafts.csswg.org/cssom/#dom-cssrule-type: 0 for the rule types that have no legacy type.

public virtual ushort Type { get; }

Methods

NameDescription
ToCss(CssFormatter?)Returns the text of the rule, formatted by formatter (CssFormatter.Default when null, which returns the same text as CssRule.CssText).
ToCss(TextWriter, CssFormatter?)Same as CssRule.ToCss, but writes the text to output instead of building a string.

ToCss overloads

ToCss(CssFormatter?)

CssRule.Formatting.cs

Returns the text of the rule, formatted by formatter (CssFormatter.Default when null, which returns the same text as CssRule.CssText).

public string ToCss(CssFormatter? formatter = null)
Parameters
formatter CssFormatter?
Returns

string

ToCss(TextWriter, CssFormatter?)

CssRule.Formatting.cs

Same as CssRule.ToCss, but writes the text to output instead of building a string.

public void ToCss(TextWriter output, CssFormatter? formatter = null)
Parameters
output TextWriter
formatter CssFormatter?

Constants

NameDescription
CharsetRuleThe value of CssRule.Type for @charset rules (CHARSET_RULE).
CounterStyleRuleThe value of CssRule.Type for @counter-style rules (COUNTER_STYLE_RULE).
FontFaceRuleThe value of CssRule.Type for @font-face rules (FONT_FACE_RULE).
FontFeatureValuesRuleThe value of CssRule.Type for @font-feature-values rules (FONT_FEATURE_VALUES_RULE).
ImportRuleThe value of CssRule.Type for @import rules (IMPORT_RULE).
KeyframeRuleThe value of CssRule.Type for keyframe rules (KEYFRAME_RULE).
KeyframesRuleThe value of CssRule.Type for @keyframes rules (KEYFRAMES_RULE).
MarginRuleThe value of CssRule.Type for page margin rules (MARGIN_RULE).
MediaRuleThe value of CssRule.Type for @media rules (MEDIA_RULE).
NamespaceRuleThe value of CssRule.Type for @namespace rules (NAMESPACE_RULE).
PageRuleThe value of CssRule.Type for @page rules (PAGE_RULE).
StyleRuleThe value of CssRule.Type for style rules (STYLE_RULE).
SupportsRuleThe value of CssRule.Type for @supports rules (SUPPORTS_RULE).

CharsetRule

The value of CssRule.Type for @charset rules (CHARSET_RULE).

public const ushort CharsetRule = 2

CounterStyleRule

The value of CssRule.Type for @counter-style rules (COUNTER_STYLE_RULE).

public const ushort CounterStyleRule = 11

FontFaceRule

The value of CssRule.Type for @font-face rules (FONT_FACE_RULE).

public const ushort FontFaceRule = 5

FontFeatureValuesRule

The value of CssRule.Type for @font-feature-values rules (FONT_FEATURE_VALUES_RULE).

public const ushort FontFeatureValuesRule = 14

ImportRule

The value of CssRule.Type for @import rules (IMPORT_RULE).

public const ushort ImportRule = 3

KeyframeRule

The value of CssRule.Type for keyframe rules (KEYFRAME_RULE).

public const ushort KeyframeRule = 8

KeyframesRule

The value of CssRule.Type for @keyframes rules (KEYFRAMES_RULE).

public const ushort KeyframesRule = 7

MarginRule

The value of CssRule.Type for page margin rules (MARGIN_RULE).

public const ushort MarginRule = 9

MediaRule

The value of CssRule.Type for @media rules (MEDIA_RULE).

public const ushort MediaRule = 4

NamespaceRule

The value of CssRule.Type for @namespace rules (NAMESPACE_RULE).

public const ushort NamespaceRule = 10

PageRule

The value of CssRule.Type for @page rules (PAGE_RULE).

public const ushort PageRule = 6

StyleRule

The value of CssRule.Type for style rules (STYLE_RULE).

public const ushort StyleRule = 1

SupportsRule

The value of CssRule.Type for @supports rules (SUPPORTS_RULE).

public const ushort SupportsRule = 12