1e41f4b71Sopenharmony_ci# div 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<div>** component is a basic container that is used as the root node of the page structure or is used to group the content. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciSupported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 19e41f4b71Sopenharmony_ci| id | string | - | No| Unique ID of the component.| 20e41f4b71Sopenharmony_ci| style | string | - | No| Style declaration of the component.| 21e41f4b71Sopenharmony_ci| class | string | - | No| Style class of the component, which is used to refer to a style table.| 22e41f4b71Sopenharmony_ci| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.| 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## Events 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Parameter| Description| 28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 29e41f4b71Sopenharmony_ci| click | - | Triggered when the component is clicked.| 30e41f4b71Sopenharmony_ci| longpress | - | Triggered when the component is long pressed.| 31e41f4b71Sopenharmony_ci| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component.| 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## Styles 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 38e41f4b71Sopenharmony_ci| flex-direction | string | row | No| Main axis direction of the flex container, which defines how items are placed in the container. Available values are as follows:<br>- **column**: Items are placed vertically from top to bottom.<br>- **row**: Items are placed horizontally from left to right.| 39e41f4b71Sopenharmony_ci| flex-wrap | string | nowrap | No| Whether items in the flex container are displayed in a single line or multiple lines. The value cannot be dynamically updated. Available values are as follows:<br>- **nowrap**: Flex items are displayed in a single line.<br>- **wrap**: Flex items are displayed in multiple lines.| 40e41f4b71Sopenharmony_ci| justify-content | string | flex-start | No| How items are aligned along the main axis of the flex container. Available values are as follows:<br>- **flex-start**: Items are packed toward the start edge of the container along the main axis.<br>- **flex-end**: Items are packed toward the end edge of the container along the main axis.<br>- **center**: Items are packed toward the center of the container along the main axis.<br>- **space-between**: Items are positioned with space between the rows.<br>- **space-around**: Items are positioned with space before, between, and after the rows.| 41e41f4b71Sopenharmony_ci| align-items | string | stretch<sup>5+</sup><br>flex-start<sup>1-4</sup> | No| How items are aligned along the cross axis in a flex container. Available values are as follows:<br>- **stretch**: Items are stretched to the same height or width as the container along the cross axis.<sup>5+</sup><br>- **flex-start**: Items are packed toward the start edge of the cross axis.<br>- **flex-end**: Items are packed toward the end edge of the cross axis.<br>- **center**: Items are packed toward the center of the cross axis.| 42e41f4b71Sopenharmony_ci| display | string | flex | No| Type of the view box of the item. The value cannot be dynamically updated. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| 43e41f4b71Sopenharmony_ci| width | <length> \| <percentage><sup>5+</sup> | - | No| Component width.<br><br>If this attribute is not set, the default value **0** is used.| 44e41f4b71Sopenharmony_ci| height | <length> \| <percentage><sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | 45e41f4b71Sopenharmony_ci| padding | <length> | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| 46e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | <length> | 0 | No| Left, top, right, and bottom padding.| 47e41f4b71Sopenharmony_ci| margin | <length> \| <percentage><sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| 48e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.| 49e41f4b71Sopenharmony_ci| border-width | <length> | 0 | No| Shorthand attribute to set the margin for all sides.| 50e41f4b71Sopenharmony_ci| border-color | <color> | black | No| Shorthand attribute to set the color for all borders.| 51e41f4b71Sopenharmony_ci| border-radius | <length> | - | No| Radius of round-corner borders.| 52e41f4b71Sopenharmony_ci| background-color | <color> | - | No| Background color.| 53e41f4b71Sopenharmony_ci| opacity<sup>5+</sup> | number | 1 | No| Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent.| 54e41f4b71Sopenharmony_ci| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. | 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci## Example 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci1. Flex style 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci ```html 62e41f4b71Sopenharmony_ci <!-- xxx.hml --> 63e41f4b71Sopenharmony_ci <div class="container"> 64e41f4b71Sopenharmony_ci <div class="flex-box"> 65e41f4b71Sopenharmony_ci <div class="flex-item color-primary"></div> 66e41f4b71Sopenharmony_ci <div class="flex-item color-warning"></div> 67e41f4b71Sopenharmony_ci <div class="flex-item color-success"></div> 68e41f4b71Sopenharmony_ci </div> 69e41f4b71Sopenharmony_ci </div> 70e41f4b71Sopenharmony_ci ``` 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci ```css 74e41f4b71Sopenharmony_ci /* xxx.css */ 75e41f4b71Sopenharmony_ci .container { 76e41f4b71Sopenharmony_ci flex-direction: column; 77e41f4b71Sopenharmony_ci justify-content: center; 78e41f4b71Sopenharmony_ci align-items: center; 79e41f4b71Sopenharmony_ci width: 454px; 80e41f4b71Sopenharmony_ci height: 454px; 81e41f4b71Sopenharmony_ci } 82e41f4b71Sopenharmony_ci .flex-box { 83e41f4b71Sopenharmony_ci justify-content: space-around; 84e41f4b71Sopenharmony_ci align-items: center; 85e41f4b71Sopenharmony_ci width: 400px; 86e41f4b71Sopenharmony_ci height: 140px; 87e41f4b71Sopenharmony_ci background-color: #ffffff; 88e41f4b71Sopenharmony_ci } 89e41f4b71Sopenharmony_ci .flex-item { 90e41f4b71Sopenharmony_ci width: 120px; 91e41f4b71Sopenharmony_ci height: 120px; 92e41f4b71Sopenharmony_ci border-radius: 16px; 93e41f4b71Sopenharmony_ci } 94e41f4b71Sopenharmony_ci .color-primary { 95e41f4b71Sopenharmony_ci background-color: #007dff; 96e41f4b71Sopenharmony_ci } 97e41f4b71Sopenharmony_ci .color-warning { 98e41f4b71Sopenharmony_ci background-color: #ff7500; 99e41f4b71Sopenharmony_ci } 100e41f4b71Sopenharmony_ci .color-success { 101e41f4b71Sopenharmony_ci background-color: #41ba41; 102e41f4b71Sopenharmony_ci } 103e41f4b71Sopenharmony_ci ``` 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci  106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci2. Flex wrap style 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci ```html 110e41f4b71Sopenharmony_ci <!-- xxx.hml --> 111e41f4b71Sopenharmony_ci <div class="container"> 112e41f4b71Sopenharmony_ci <div class="flex-box"> 113e41f4b71Sopenharmony_ci <div class="flex-item color-primary"></div> 114e41f4b71Sopenharmony_ci <div class="flex-item color-warning"></div> 115e41f4b71Sopenharmony_ci <div class="flex-item color-success"></div> 116e41f4b71Sopenharmony_ci </div> 117e41f4b71Sopenharmony_ci </div> 118e41f4b71Sopenharmony_ci ``` 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci ```css 122e41f4b71Sopenharmony_ci /* xxx.css */ 123e41f4b71Sopenharmony_ci .container { 124e41f4b71Sopenharmony_ci flex-direction: column; 125e41f4b71Sopenharmony_ci justify-content: center; 126e41f4b71Sopenharmony_ci align-items: center; 127e41f4b71Sopenharmony_ci width: 454px; 128e41f4b71Sopenharmony_ci height: 454px; 129e41f4b71Sopenharmony_ci } 130e41f4b71Sopenharmony_ci .flex-box { 131e41f4b71Sopenharmony_ci justify-content: space-around; 132e41f4b71Sopenharmony_ci align-items: center; 133e41f4b71Sopenharmony_ci flex-wrap: wrap; 134e41f4b71Sopenharmony_ci width: 300px; 135e41f4b71Sopenharmony_ci height: 250px; 136e41f4b71Sopenharmony_ci background-color: #ffffff; 137e41f4b71Sopenharmony_ci } 138e41f4b71Sopenharmony_ci .flex-item { 139e41f4b71Sopenharmony_ci width: 120px; 140e41f4b71Sopenharmony_ci height: 120px; 141e41f4b71Sopenharmony_ci border-radius: 16px; 142e41f4b71Sopenharmony_ci } 143e41f4b71Sopenharmony_ci .color-primary { 144e41f4b71Sopenharmony_ci background-color: #007dff; 145e41f4b71Sopenharmony_ci } 146e41f4b71Sopenharmony_ci .color-warning { 147e41f4b71Sopenharmony_ci background-color: #ff7500; 148e41f4b71Sopenharmony_ci } 149e41f4b71Sopenharmony_ci .color-success { 150e41f4b71Sopenharmony_ci background-color: #41ba41; 151e41f4b71Sopenharmony_ci } 152e41f4b71Sopenharmony_ci ``` 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci  155