Table of Contents

Class CssMediaQueryList

Namespace
Egami.Css
Assembly
Egami.Css.dll

A media query list (Media Queries 4), such as screen and (min-width: 600px), print.

public sealed class CssMediaQueryList
Inheritance
CssMediaQueryList
Inherited Members

Examples

// Media Queries 4: types, features, min-/max- and range syntax. Unknown features count as false.
var phone = new CssMediaContext { Width = 390, Height = 844, Resolution = 3, PrefersColorScheme = "dark" };
bool narrow = CssMediaQueryList.Parse("screen and (width < 600px)").Matches(phone);
bool dark = CssMediaQueryList.Parse("(prefers-color-scheme: dark) and (min-resolution: 2dppx)").Matches(phone);

// Features the context does not know go to a hook.
CssMediaContext touch = phone with { Feature = (name, value) => name == "pointer" ? value?[0].ToString() == "coarse" : null };
bool coarse = CssMediaQueryList.Parse("(pointer: coarse)").Matches(touch);

Remarks

A query that does not parse becomes not all without affecting the others; a feature the context does not know, or any syntax Media Queries 4 reserves for the future, evaluates as unknown, which counts as false. An empty list matches.

Properties

Count

Gets the number of media queries in the list.

public int Count { get; }

Property Value

int

MediaText

Gets the media query list as CSS text.

public string MediaText { get; }

Property Value

string

Methods

Matches(CssMediaContext)

Evaluates the list: true when any query matches, or when the list is empty.

public bool Matches(CssMediaContext context)

Parameters

context CssMediaContext

The media context.

Returns

bool

True when the list matches.

Parse(string)

Parses a media query list. Never throws: a query that does not parse becomes not all.

public static CssMediaQueryList Parse(string text)

Parameters

text string

The media query list, such as (prefers-color-scheme: dark).

Returns

CssMediaQueryList

The list.

ToString()

Returns the list as CSS text.

public override string ToString()

Returns

string

The text.