# Stylesheet
Class
## About
`Stylesheet` collects CSS rules by selector. Adding declarations to a selector that already has a rule merges them into that rule, and setting a property that is already set replaces its value in place. `ToString` writes one block per selector in the order the selectors were first added.
`Editor.ExportStylesheet` builds one for HTML export. Node types add their rules in `Node.ExportStyles`.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| AddCSS | css As String | (None) | Adds the rules in the supplied CSS text, merging declarations into existing rules with the same selector. |
| AddRule | selector As String <br> declarations As String | (None) | Adds declarations such as "color: red; margin: 0" to the rule for the supplied selector, creating the rule when needed. |
| HasRule | selector As String | Boolean | Returns True when the stylesheet has a rule for the supplied selector. |
| PropertyValue | selector As String <br> propertyName As String | String | Returns the value of a property in the rule for the supplied selector, or an empty string when it is not set. |
| RuleCount | (None) | Integer | Returns the number of rules in the stylesheet, not counting at-rules. |
| SelectorAt | index As Integer | String | Returns the selector of the rule at the supplied zero-based index. |
| SetProperty | selector As String <br> propertyName As String <br> value As String | (None) | Sets a property in the rule for the supplied selector. A property that is already set keeps its position and takes the new value. |
| ToString | (None) | String | Returns the stylesheet as CSS text, one rule per block in the order the rules were first added. |
## Notes
Selectors are compared after collapsing spaces, and case-sensitively, so `th,td` and `th, td` share one rule, but `th, td`, `td, th`, and `TH, TD` are separate rules. Property names are stored in lowercase.
`AddCSS` reads ordinary rules and drops comments. At-rules such as `@media` are kept as written and placed after the ordinary rules; their contents are not merged.
## Examples
```xojo
Var sheet As New GraffitiProEditor.Stylesheet
sheet.AddRule("table", "width: 100%; border-collapse: collapse")
sheet.SetProperty("th", "font-weight", "700")
sheet.AddCSS("th, td { padding: 10px; }")
Var css As String = sheet.ToString
```