Expand description

CSS rules.

The CssRule enum includes all supported rules, and can be used to parse and serialize rules from CSS. Lists of rules (i.e. within a stylesheet, or inside another rule such as @media) are represented by CssRuleList.

Each rule includes a source location, which indicates the line and column within the source file where it was parsed. This is used when generating source maps.

Example

This example shows how you could parse a single CSS rule, and serialize it to a string.

use parcel_css::{
  rules::CssRule,
  traits::ToCss,
  stylesheet::{ParserOptions, PrinterOptions}
};

let rule = CssRule::parse_string(
  ".foo { color: red; }",
  ParserOptions::default()
).unwrap();

assert_eq!(
  rule.to_css_string(PrinterOptions::default()).unwrap(),
  ".foo {\n  color: red;\n}"
);

If you have a cssparser::Parser already, you can also use the parse and to_css methods instead, rather than parsing from a string.

See StyleSheet to parse an entire file of multiple rules.

Modules

The @counter-style rule.

The @custom-media rule.

The @-moz-document rule.

The @font-face rule.

The @font-palette-values rule.

The @import rule.

The @keyframes rule.

The @layer rule.

The @media rule.

The @namespace rule.

The @nest rule.

The @page rule.

The @property rule.

Style rules.

The @supports rule.

The @viewport rule.

Structs

A list of CSS rules.

A source location.

Enums

A CSS rule.