Table of Contents

Class CssSelectorList

Namespace
Egami.Css
Assembly
Egami.Css.dll

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

IReadOnlyList<CssSelector>

Text

Gets the list as CSS text.

public string Text { get; }

Property Value

string

Methods

Matches(ICssElement, ICssElement?)

Tests whether any selector in the list matches an element.

public bool Matches(ICssElement element, ICssElement? scope = null)

Parameters

element ICssElement

The element.

scope ICssElement

The scoping root for :scope, or null to make :scope match 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

text string

The selectors, such as a:hover, .note > p.

namespaces CssNamespaces

The 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

text string

The selectors.

list CssSelectorList

The selector list, when valid.

namespaces CssNamespaces

The namespace prefixes the selectors may use, or null for none.

Returns

bool

True when the text is a valid selector list.