Class CssSelectorList
A selector list (Selectors 4), such as a style rule's prelude or the argument of querySelectorAll.
public sealed class CssSelectorList
- Inheritance
-
CssSelectorList
- Inherited Members
Examples
// Selectors 4, matched right to left over ICssElement.
CssSelectorList list = CssSelectorList.Parse("g.layer > rect:first-child, :is(circle, ellipse)");
bool matches = list.Matches(rect);
CssSelector selector = list.Selectors[0];
CssSpecificity specificity = selector.Specificity; // (0, 2, 2)
// Namespace prefixes, as @namespace declares them.
var namespaces = new CssNamespaces();
namespaces.Set("svg", "http://www.w3.org/2000/svg");
bool inSvg = CssSelectorList.Parse("svg|rect", namespaces).Matches(rect);
// A pseudo-element never matches the element itself; the cascade asks for it by name.
CssSelector before = CssSelectorList.Parse("rect::before").Selectors[0];
bool beforeMatches = before.MatchesPseudoElement(rect, "before");
bool valid = CssSelectorList.TryParse("rect:nonsense", out _); // false: unknown pseudo-classes are invalid
Properties
Selectors
Gets the complex selectors, in order.
public IReadOnlyList<CssSelector> Selectors { get; }
Property Value
Text
Gets the list as CSS text.
public string Text { get; }
Property Value
Methods
Matches(ICssElement, ICssElement?)
Tests whether any selector in the list matches an element.
public bool Matches(ICssElement element, ICssElement? scope = null)
Parameters
elementICssElementThe element.
scopeICssElementThe scoping root for
:scope, or null to make:scopematch the root element.
Returns
- bool
True when a selector without a pseudo-element matches.
Parse(string, CssNamespaces?)
Parses a selector list.
public static CssSelectorList Parse(string text, CssNamespaces? namespaces = null)
Parameters
textstringThe selectors, such as
a:hover, .note > p.namespacesCssNamespacesThe namespace prefixes the selectors may use, or null for none.
Returns
- CssSelectorList
The selector list.
Exceptions
- FormatException
The text is not a valid selector list.
ToString()
Returns the list as CSS text.
public override string ToString()
Returns
- string
The text.
TryParse(string, out CssSelectorList?, CssNamespaces?)
Parses a selector list, without throwing.
public static bool TryParse(string text, out CssSelectorList? list, CssNamespaces? namespaces = null)
Parameters
textstringThe selectors.
listCssSelectorListThe selector list, when valid.
namespacesCssNamespacesThe namespace prefixes the selectors may use, or null for none.
Returns
- bool
True when the text is a valid selector list.