pub struct Style {
pub css: String,
/* private fields */
}
Expand description
Represents a <style>
child in the <head>
element containing CSS.
css
: formatted css String.
Fields§
§css: String
Implementations§
Source§impl Style
impl Style
Sourcepub fn delete(self) -> Result<(), WasmCssError>
pub fn delete(self) -> Result<(), WasmCssError>
Delete Style
, removing it from the DOM.
Returns error if missing access to: Head
, Window
, Document
.
Example Usage:
let mut style = style!("background-color: blue;")?;
style.delete()?;
Source§impl Style
impl Style
Sourcepub fn extend_from_css(&mut self, new_css: &str) -> Result<(), WasmCssError>
pub fn extend_from_css(&mut self, new_css: &str) -> Result<(), WasmCssError>
Extend Style
with css
, re-rendering if new_css
is not empty.
Returns error if missing access to: Head
, Window
, Document
.
Example Usage:
let mut style = named_style!(
"my_style",
"
font-size: 10rem;
background-color: blue;
"
)?;
style.extend_from_css("font-size: 30rem; display: flex;")?;
Source§impl Style
impl Style
Sourcepub fn extend_from_style(&mut self, s2: &Style) -> Result<(), WasmCssError>
pub fn extend_from_style(&mut self, s2: &Style) -> Result<(), WasmCssError>
Extend Style
with Style
, re-rendering if s2
is not empty.
Returns error if missing access to: Head
, Window
, Document
.
Example Usage:
let mut style1 = named_style!(
"my_style",
"
display: flex;
flex-direction: row;
"
)?;
let style2 = style!(
"
color: red;
flex-direction: column;
"
)?;
style1.extend_from_style(&style2)?;
Source§impl Style
impl Style
Sourcepub fn remove_keys<K: Into<String>>(
&mut self,
keys: Vec<K>,
) -> Result<(), WasmCssError>
pub fn remove_keys<K: Into<String>>( &mut self, keys: Vec<K>, ) -> Result<(), WasmCssError>
Remove keys
from Style
, re-rendering if at-least one key is removed.
Returns error if missing access to: Head
, Window
, Document
.
Example Usage:
let mut style = named_style!(
"my_style",
"
font-size: 18px;
&:hover {{
background-color: red;
}}
background-color: blue;
"
)?;
style.remove_keys(vec!["font-size", "&:hover"])?;
Source§impl Style
impl Style
Sourcepub fn new(css: &str, css_name: Option<&str>) -> Result<Self, WasmCssError>
pub fn new(css: &str, css_name: Option<&str>) -> Result<Self, WasmCssError>
Create a Style
from css
, rendering it to the DOM as a <style>
in <head>
.
The css
is formatted, minfied, and small errors like invalid semi-colons can be
corrected, however invalid CSS itself is not handled by the parser.
Effects remain there order as defined, but their inner fields, as well as the Style’s fields will be ordered in a deterministic fashion to avoid duplication.
Note: Trailing semi-colons are required.
Returns error if missing access to: Head
, Crypto
(If generating a random ID),
Window
, Document
.
Provide css_name
to define a class, ID, or to target a global identifier,
E.G.: div
, #id
, .class
.
Example Usage:
let style = Style::new(
"
display: flex;
&:hover {
background-color: rgba(111, 111, 111, 0.1);
}
@media (max-width: 800px) {
flex-direction: column;
}
",
Some(".my_class"),
)?;
Sourcepub fn identity(&self) -> &str
pub fn identity(&self) -> &str
Returns the identity
of the definition inside the <style>
element.
Example Usage:
let style = named_style!(".myStyle", "font-size: 5rem;")?;
// "myStyle"
let identity = style.identity();
let style = named_style!("#myStyle", "font-size: 5rem;")?;
// "myStyle"
let identity = style.identity();
let style = named_style!("body", "font-size: 5rem;")?;
// "body"
let identity = style.identity();