mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 06:30:20 +00:00
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
//! Example: Inline Styles
|
|
//! ----------------------
|
|
//!
|
|
//! This example shows how to use inline styles in Dioxus components.
|
|
//!
|
|
//! Inline styles function very similarly to regular attributes, just grouped together in "style".
|
|
//!
|
|
//! Inline styles in Dioxus are more performant than React since we're able to cache attributes and compare by pointers.
|
|
//! However, it's still not as performant as cascaded styles. Use with care.
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
pub fn Example(cx: Scope) -> Element {
|
|
cx.render(rsx! {
|
|
head {
|
|
style: { background_color: "powderblue" }
|
|
}
|
|
body {
|
|
h1 { style: { color: "blue" }
|
|
"This is a heading"
|
|
}
|
|
p { style: { color: "red" }
|
|
"This is a paragraph"
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// .... technically the rsx! macro is slightly broken at the moment and allows styles not wrapped in style {}
|
|
// I haven't noticed any name collisions yet, and am tentatively leaving this behavior in..
|
|
// Don't rely on it.
|
|
pub fn Example2(cx: Scope) -> Element {
|
|
cx.render(rsx! {
|
|
div { color: "red"
|
|
"hello world!"
|
|
}
|
|
})
|
|
}
|