CssStyleSheet Class
https://drafts.csswg.org/cssom/#the-cssstylesheet-interface
public sealed class CssStyleSheet : StyleSheet- Inheritance
StyleSheetCssStyleSheet
Constructors
| Name | Description |
|---|---|
| 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.csCreates a constructed style sheet (https://drafts.csswg.org/cssom/#dom-cssstylesheet-cssstylesheet).
public CssStyleSheet(CssStyleSheetInit? options = null)CssStyleSheet(Document, CssStyleSheetInit?)
CssStyleSheet.csCreates 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
constructorDocumentDocumentoptionsCssStyleSheetInit?
Properties
| Name | Description |
|---|---|
| CssRules | Gets the list of the CSS rules of the style sheet. |
| OwnerRule | https://drafts.csswg.org/cssom/#dom-cssstylesheet-ownerrule: the @import rule that imports this style sheet. |
| Rules | Gets the list of the CSS rules of the style sheet (legacy alias of cssRules). |
CssRules
CssStyleSheet.csGets the list of the CSS rules of the style sheet.
public CssRuleList CssRules { get; }OwnerRule
CssStyleSheet.cshttps://drafts.csswg.org/cssom/#dom-cssstylesheet-ownerrule: the @import rule that imports this style sheet.
public CssRule? OwnerRule { get; }Rules
CssStyleSheet.csGets the list of the CSS rules of the style sheet (legacy alias of cssRules).
public CssRuleList Rules { get; }Methods
| Name | Description |
|---|---|
| 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.csDeleteRule(uint)
CssStyleSheet.csRemoves the rule at the given index from the style sheet.
InsertRule(string, uint)
CssStyleSheet.csRemoveRule(uint)
CssStyleSheet.csRemoves the rule at the given index from the style sheet (legacy alias of deleteRule()).
Replace(string)
CssStyleSheet.cshttps://drafts.csswg.org/cssom/#dom-cssstylesheet-replace: the style sheet is parsed synchronously.
public Task<CssStyleSheet> Replace(string text)ReplaceSync(string)
CssStyleSheet.csSynchronously replaces the rules of a constructed style sheet with the rules parsed from the given text.
ToCss overloads
ToCss(CssFormatter?)
CssStyleSheet.Formatting.csReturns the text of the rules of the style sheet, formatted by formatter (CssFormatter.Default when null).
public string ToCss(CssFormatter? formatter = null)ToCss(TextWriter, CssFormatter?)
CssStyleSheet.Formatting.csSame as CssStyleSheet.ToCss, but writes the text to output instead of building a string.
public void ToCss(TextWriter output, CssFormatter? formatter = null)Parameters
outputTextWriterformatterCssFormatter?