Class CssSupportsRule
An @supports rule: rules that apply when the condition holds.
public sealed class CssSupportsRule : CssRule
- Inheritance
-
CssSupportsRule
- Inherited Members
Examples
// Parsing never throws on bad CSS: it recovers as CSS Syntax 3 says and reports each problem.
var errors = new List<CssParseError>();
var options = new CssParseOptions { Errors = errors.Add };
CssStyleSheet sheet = CssStyleSheet.Parse("""
@import url(print.css) print;
@namespace svg url(http://www.w3.org/2000/svg);
rect.note, svg|circle { fill: gold !important; stroke: #333 }
@media (max-width: 600px) { rect { stroke-width: 2px } }
@supports (display: grid) { g { display: grid } }
@font-face { font-family: "Inter"; src: url(inter.woff2) format("woff2") }
@layer base { text { fill: gray } }
@keyframes spin { to { rotate: 1turn } }
p:unknown { color: red }
""", options);
foreach (CssRule rule in sheet.Rules)
{
switch (rule)
{
case CssStyleRule style:
Console.WriteLine($"{style.SelectorText}: {style.Declarations.Count} declarations");
break;
case CssMediaRule media:
Console.WriteLine($"@media {media.Media.MediaText}: {media.Rules.Count} rules");
break;
case CssSupportsRule supports:
Console.WriteLine($"@supports {supports.ConditionText}");
break;
case CssFontFaceRule fontFace:
Console.WriteLine($"@font-face {fontFace.FontFace.Family}");
break;
case CssImportRule import:
Console.WriteLine($"@import {import.Url} for {import.Media.MediaText}");
break;
case CssNamespaceRule ns:
Console.WriteLine($"@namespace {ns.Prefix} = {ns.Uri}");
break;
case CssLayerRule layer:
Console.WriteLine($"@layer {string.Join(", ", layer.Names)}");
break;
case CssUnknownAtRule other:
Console.WriteLine($"@{other.Name} (kept, not interpreted)");
break;
}
}
// The rule with ':unknown' was dropped and reported.
CssParseError dropped = errors[0];
Console.WriteLine($"{dropped.Line}:{dropped.Column} {dropped.Message}");
Properties
ConditionText
Gets the condition as CSS text.
public string ConditionText { get; }
Property Value
IsValid
Gets whether the condition parsed. A rule whose condition does not parse never matches.
public bool IsValid { get; }
Property Value
Rules
Gets the rules inside.
public IReadOnlyList<CssRule> Rules { get; }
Property Value
Methods
Matches(Func<CssDeclaration, bool>)
Evaluates the condition. selector() tests are answered by this package's selector parser; font-tech(),
font-format() and unknown syntax are false.
public bool Matches(Func<CssDeclaration, bool> supports)
Parameters
supportsFunc<CssDeclaration, bool>Answers whether a declaration such as
(display: grid)is supported.
Returns
- bool
True when the condition holds.