inline_styles.rs 818 B

1234567891011121314151617181920212223242526272829
  1. //! Example: Inline Styles
  2. //! ----------------------
  3. //!
  4. //! This example shows how to use inline styles in Dioxus components.
  5. //!
  6. //! Inline styles function very similarly to regular attributes, just grouped together in "style".
  7. //!
  8. //! Inline styles in Dioxus are more performant than React since we're able to cache attributes and compare by pointers.
  9. //! However, it's still not as performant as cascaded styles. Use with care.
  10. use dioxus::prelude::*;
  11. pub fn Example(cx: Scope) -> Element {
  12. cx.render(rsx! {
  13. head {
  14. background_color: "powderblue"
  15. }
  16. body {
  17. h1 {
  18. color: "blue",
  19. "This is a heading"
  20. }
  21. p {
  22. color: "red",
  23. "This is a paragraph"
  24. }
  25. }
  26. })
  27. }