pub enum Size {
Zero,
Px(u32),
Percent(f32),
Em(f32),
Rem(f32),
Vw(f32),
Vh(f32),
Auto,
Var(CssVar),
}Expand description
Represents size and length values for CSS properties.
The Size enum provides a type-safe way to specify sizes in CSS. It supports
various unit types including absolute units (like pixels), relative units
(like percentages, em, rem), viewport-relative units, and special values like
Auto and Zero.
This enum is used for properties like width, height, margin, padding, font-size, and any other CSS property that accepts a size or length value.
§Examples
use mew_css::style;
use mew_css::values::Size;
// Using pixel values (absolute)
let css1 = style().width(Size::Px(200)).apply();
// Using percentage values (relative to parent)
let css2 = style().width(Size::Percent(50.0)).apply();
// Using em values (relative to element's font size)
let css3 = style().margin(Size::Em(1.5)).apply();
// Using rem values (relative to root font size)
let css4 = style().font_size(Size::Rem(1.2)).apply();
// Using viewport-relative units
let css5 = style()
.width(Size::Vw(100.0)) // 100% of viewport width
.height(Size::Vh(50.0)) // 50% of viewport height
.apply();
// Using special values
let css6 = style()
.margin(Size::Auto) // Auto margins (useful for centering)
.border_width(Size::Zero) // Zero (equivalent to 0px)
.apply();Variants§
Zero
Zero value (equivalent to 0px)
Px(u32)
Pixel values - absolute length in pixels
Percent(f32)
Percentage values - relative to parent element
Em(f32)
Em values - relative to the element’s font size
Rem(f32)
Rem values - relative to the root element’s font size
Vw(f32)
Viewport width percentage - relative to viewport width
Vh(f32)
Viewport height percentage - relative to viewport height
Auto
Auto value - browser determines the appropriate size
Var(CssVar)
CSS variable reference