pub struct CssVar(/* private fields */);Expand description
Represents a reference to a CSS custom property (CSS variable).
The CssVar struct allows you to reference CSS variables in your styles.
When displayed, it formats the variable name as var(--name), which is
the correct syntax for using CSS variables in property values.
CSS variables provide a way to store values that can be reused throughout a document. They help maintain consistency and make it easier to update styles globally.
§Examples
use mew_css::variable::{CssVar, var};
use mew_css::style;
use mew_css::values::Color;
// Create a CSS variable reference
let primary_color = CssVar::new("primary-color");
// Use it in a style
let css = style()
.color(Color::Var(primary_color))
.apply();
assert_eq!(css, "color: var(--primary-color);");
// The shorter way using the `var` function and `into()`
let css = style()
.color(var("primary-color").into())
.apply();
assert_eq!(css, "color: var(--primary-color);");Implementations§
Source§impl CssVar
impl CssVar
Sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Creates a new CSS variable reference.
This method creates a reference to a CSS variable that can be used in
property values. The variable name can be provided with or without the
-- prefix; if it’s missing, it will be added automatically.
§Arguments
name- The variable name (with or without the--prefix)
§Returns
A new CssVar instance
§Examples
use mew_css::variable::CssVar;
// These are equivalent
let var1 = CssVar::new("primary-color");
let var2 = CssVar::new("--primary-color");Trait Implementations§
Source§impl From<CssVar> for AlignItems
impl From<CssVar> for AlignItems
Source§impl From<CssVar> for BorderStyle
impl From<CssVar> for BorderStyle
Source§impl From<CssVar> for FlexDirection
impl From<CssVar> for FlexDirection
Source§impl From<CssVar> for FontWeight
impl From<CssVar> for FontWeight
Source§impl From<CssVar> for JustifyContent
impl From<CssVar> for JustifyContent
Source§impl From<CssVar> for LineHeight
impl From<CssVar> for LineHeight
Source§impl From<CssVar> for TextDecoration
impl From<CssVar> for TextDecoration
Source§impl From<CssVar> for Visibility
impl From<CssVar> for Visibility
impl StructuralPartialEq for CssVar
Auto Trait Implementations§
impl Freeze for CssVar
impl RefUnwindSafe for CssVar
impl Send for CssVar
impl Sync for CssVar
impl Unpin for CssVar
impl UnwindSafe for CssVar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more