Expand description
Build a
<div>
element.
Part of the HTML namespace. Only works in HTML-compatible renderers
§Definition and Usage
- The
<div>tag defines a division or a section in an HTML document. - The
<div>tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. - The
<div>tag is easily styled by using the class or id attribute. - Any sort of content can be put inside the
<div>tag!
Note: By default, browsers always place a line break before and after the
element.
§References:
- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
- https://www.w3schools.com/tags/tag_div.asp
§Usage in rsx
rsx! {
// Elements are followed by braces that surround any attributes and children for that element
div {
// Add any attributes first
class: "my-class",
"custom-attribute-name": "value",
// Then add any attributes you are spreading into this element
..attributes,
// Then add any children elements, components, text nodes, or raw expressions
div {}
ChildComponent {}
"child text"
{raw_expression}
}
};Constants§
- The HTML class attribute is used to specify a class for an HTML element.
- dangerous_inner_html is Dioxus’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from Dioxus, but you have to type out dangerous_inner_html to remind yourself that it’s dangerous
- prevent_
default Deprecated This attribute has been deprecated in favor ofdioxus_core::Event::prevent_default