Module rules

Source
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 lightningcss::{
  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§

container
The @container rule.
counter_style
The @counter-style rule.
custom_media
The @custom-media rule.
document
The @-moz-document rule.
font_face
The @font-face rule.
font_feature_values
The @font-feature-values rule.
font_palette_values
The @font-palette-values rule.
import
The @import rule.
keyframes
The @keyframes rule.
layer
The @layer rule.
media
The @media rule.
namespace
The @namespace rule.
nesting
The @nest rule.
page
The @page rule.
property
The @property rule.
scope
The @scope rule.
starting_style
The @starting-style rule.
style
Style rules.
supports
The @supports rule.
unknown
An unknown at-rule.
view_transition
The @view-transition rule.
viewport
The @viewport rule.

Structs§

CssRuleList
A list of CSS rules.
Location
A source location.

Enums§

CssRule
A CSS rule.