dioxus/examples/core_reference/global_css.rs

31 lines
793 B
Rust
Raw Normal View History

2021-07-12 06:23:46 +00:00
//! Examples: CSS
//! -------------
//!
//! Originally taken from:
//! - https://www.w3schools.com/html/tryit.asp?filename=tryhtml_css_internal
//!
//! Include global styles in your app!
//!
//! You can simply drop in a "style" tag and set the inner contents to your stylesheet.
//! It's slightly more manual than React, but is less magical.
//!
//! A coming update with the assets system will make it possible to include global css from child components.
2021-07-02 05:30:52 +00:00
use dioxus::prelude::*;
2021-07-12 06:23:46 +00:00
const STYLE: &str = r#"
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
"#;
2021-07-02 05:30:52 +00:00
pub fn Example(cx: Scope) -> Element {
2021-07-12 06:23:46 +00:00
cx.render(rsx! {
head { style { "{STYLE}" } }
body {
h1 {"This is a heading"}
p {"This is a paragraph"}
2021-07-02 05:30:52 +00:00
}
})
}