Module values

Source
Expand description

Common CSS values used across many properties.

Each value provides parsing and serialization support using the Parse and ToCss traits. In addition, many values support ways of manipulating them, including converting between representations and units, generating fallbacks for legacy browsers, minifying them, etc.

§Example

This example shows how you could parse a CSS color value, convert it to RGB, and re-serialize it. Similar patterns for parsing and serializing are possible across all value types.

use lightningcss::{
  traits::{Parse, ToCss},
  values::color::CssColor,
  printer::PrinterOptions
};

let color = CssColor::parse_string("lch(50% 75 0)").unwrap();
let rgb = color.to_rgb().unwrap();
assert_eq!(rgb.to_css_string(PrinterOptions::default()).unwrap(), "#e1157b");

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

Modules§

alpha
CSS alpha values, used to represent opacity.
angle
CSS angle values.
calc
Mathematical calculation functions and expressions.
color
CSS color values.
easing
CSS easing functions.
gradient
CSS gradient values.
ident
CSS identifiers.
image
CSS image values.
length
CSS length values.
number
CSS number values.
percentage
CSS percentage values.
position
CSS position values.
ratio
CSS ratio values.
rect
Generic values for four sided properties.
resolution
CSS resolution values.
shape
CSS shape values for masking and clipping.
size
Generic values for two component properties.
string
Types used to represent strings.
syntax
CSS syntax strings
time
CSS time values.
url
CSS url() values.