CssStyleSheet Class

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

public sealed class CssStyleSheet : StyleSheet
Inheritance
StyleSheet CssStyleSheet

Constructors

NameDescription
CssStyleSheet(CssStyleSheetInit?)Creates a constructed style sheet (https://drafts.csswg.org/cssom/#dom-cssstylesheet-cssstylesheet).
CssStyleSheet(Document, CssStyleSheetInit?)Creates a constructed style sheet whose constructor document is constructorDocument: the sheet can only be adopted by this document and the shadow roots of its tree. The IDL constructor uses the associated document of the current global object, which is the document of the script's window when a script runs.

CssStyleSheet overloads

CssStyleSheet(CssStyleSheetInit?)

CssStyleSheet.cs

Creates a constructed style sheet (https://drafts.csswg.org/cssom/#dom-cssstylesheet-cssstylesheet).

public CssStyleSheet(CssStyleSheetInit? options = null)

CssStyleSheet(Document, CssStyleSheetInit?)

CssStyleSheet.cs

Creates a constructed style sheet whose constructor document is constructorDocument: the sheet can only be adopted by this document and the shadow roots of its tree. The IDL constructor uses the associated document of the current global object, which is the document of the script's window when a script runs.

public CssStyleSheet(Document constructorDocument, CssStyleSheetInit? options = null)
Parameters
constructorDocument Document
options CssStyleSheetInit?

Properties

NameDescription
CssRulesGets the list of the CSS rules of the style sheet.
OwnerRulehttps://drafts.csswg.org/cssom/#dom-cssstylesheet-ownerrule: the @import rule that imports this style sheet.
RulesGets the list of the CSS rules of the style sheet (legacy alias of cssRules).

Gets the list of the CSS rules of the style sheet.

public CssRuleList CssRules { get; }

https://drafts.csswg.org/cssom/#dom-cssstylesheet-ownerrule: the @import rule that imports this style sheet.

public CssRule? OwnerRule { get; }

Gets the list of the CSS rules of the style sheet (legacy alias of cssRules).

public CssRuleList Rules { get; }

Methods

NameDescription
AddRule(string, string, uint?)https://drafts.csswg.org/cssom/#dom-cssstylesheet-addrule
DeleteRule(uint)Removes the rule at the given index from the style sheet.
InsertRule(string, uint)Inserts a rule, parsed from the given text, at the given index of the style sheet and returns its index.
RemoveRule(uint)Removes the rule at the given index from the style sheet (legacy alias of deleteRule()).
Replace(string)https://drafts.csswg.org/cssom/#dom-cssstylesheet-replace: the style sheet is parsed synchronously.
ReplaceSync(string)Synchronously replaces the rules of a constructed style sheet with the rules parsed from the given text.
ToCss(CssFormatter?)Returns the text of the rules of the style sheet, formatted by formatter (CssFormatter.Default when null).
ToCss(TextWriter, CssFormatter?)Same as CssStyleSheet.ToCss, but writes the text to output instead of building a string.

AddRule(string, string, uint?)

CssStyleSheet.cs

https://drafts.csswg.org/cssom/#dom-cssstylesheet-addrule

public int AddRule(string selector = "undefined", string style = "undefined", uint? index = null)

DeleteRule(uint)

CssStyleSheet.cs

Removes the rule at the given index from the style sheet.

public void DeleteRule(uint index)

InsertRule(string, uint)

CssStyleSheet.cs

Inserts a rule, parsed from the given text, at the given index of the style sheet and returns its index.

public uint InsertRule(string rule, uint index = 0U)

RemoveRule(uint)

CssStyleSheet.cs

Removes the rule at the given index from the style sheet (legacy alias of deleteRule()).

public void RemoveRule(uint index = 0U)

Replace(string)

CssStyleSheet.cs

https://drafts.csswg.org/cssom/#dom-cssstylesheet-replace: the style sheet is parsed synchronously.

public Task<CssStyleSheet> Replace(string text)

ReplaceSync(string)

CssStyleSheet.cs

Synchronously replaces the rules of a constructed style sheet with the rules parsed from the given text.

public void ReplaceSync(string text)

ToCss overloads

ToCss(CssFormatter?)

CssStyleSheet.Formatting.cs

Returns the text of the rules of the style sheet, formatted by formatter (CssFormatter.Default when null).

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

string

ToCss(TextWriter, CssFormatter?)

CssStyleSheet.Formatting.cs

Same as CssStyleSheet.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?