1e41f4b71Sopenharmony_ci# div 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_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. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **NOTE** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciSupported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciThe [universal attributes](js-service-widget-common-attributes.md) are supported. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Styles 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-service-widget-common-styles.md), the following styles are supported. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 25e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 26e41f4b71Sopenharmony_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.| 27e41f4b71Sopenharmony_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.| 28e41f4b71Sopenharmony_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.<br>- **space-evenly**<sup>5+</sup>: Items are distributed within the container along the main axis, with even space between each two.| 29e41f4b71Sopenharmony_ci| align-items | string | stretch | 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.<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.| 30e41f4b71Sopenharmony_ci| align-content | string | flex-start | No| Multi-row alignment mode when there is extra space in the cross axis. Available values are as follows:<br>- **flex-start**: All rows are packed toward the start edge of the cross axis. The start edge of the cross axis of the first row is aligned with the start edge of the cross axis of the container. All subsequent rows are aligned with the previous row.<br>- **flex-end**: All rows are packed toward the end edge of the cross axis. The end of the cross axis of the last row is aligned with the end of the cross axis of the container. All subsequent rows are aligned with the previous row.<br>- **center**: All rows are packed toward the center of the cross axis. Rows are close to each other and aligned with the center of the container. The spacing between the start edge of the container's cross axis and the first row is equal to the spacing between the end edge of the container's cross axis and the last row.<br>- **space-between**: All rows are evenly distributed in the container. The spacing between two adjacent rows is the same. The start and end edges of the container's cross axis are aligned with the edges of the first and last rows, respectively.<br>- **space-around**: All rows are evenly distributed in the container. The spacing between two adjacent rows is the same. The spacing between the start edge of the container's cross axis and the first row and that between the end edge and the last row are half of the spacing between two adjacent rows.| 31e41f4b71Sopenharmony_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| 32e41f4b71Sopenharmony_ci| grid-template-[columns\|rows] | string | 1 row, 1 column| No| Number of rows and columns in the current grid layout. If this attribute is not set, one row and one column are displayed by default. This attribute is valid only when **display** is set to **grid**.<br>Below are some example values of **grid-template-columns**:<br>- **50px 100px 60px**: There are three columns. The first column is 50 px, the second column is 100 px, and the third column is 60 px.<br>- **1fr 1fr 2fr**: There are three columns, and the width allowed by the parent component is divided into four equal shares. The first column occupies one share, the second column occupies one share, and the third column occupies two shares.<br>- **30% 20% 50%**: There are three columns. The first column occupies 30% of the total width allowed by the parent component, the second column occupies 20%, and the third column occupies 50%.<br>- **repeat (2,100px)**: There are two columns. The first column is 100 px, and the second column is 100 px.<br>- **repeat(auto-fill,100px)**<sup>5+</sup>: Each column is 100 px and repeats to fill the cross axis. The number of columns is calculated based on the column size and the cross axis size.<br>- **auto 1fr 1fr**: There are three columns. The first column is adaptive to the width required by its child components. The remaining space is divided into two equal shares, one share occupied by each of the rest two columns.| 33e41f4b71Sopenharmony_ci| grid-[columns\|rows]-gap | <length> | 0 | No| Size of the gap between two consecutive rows or columns in a grid layout. You can also use **grid-gap** to set the same size of the gap between rows and columns. This attribute is valid only when **display** is set to **grid**.| 34e41f4b71Sopenharmony_ci| grid-row-[start\|end] | number | - | No| Start and end row numbers of the current item in the grid layout. This attribute is valid only when the item's parent component is a **\<div>** container whose **display** style is set to **grid**.| 35e41f4b71Sopenharmony_ci| grid-column-[start\|end] | number | - | No| Start and end column numbers of the current item in the grid layout. This attribute is valid only when the item's parent component is a **\<div>** container whose **display** style is set to **grid**.| 36e41f4b71Sopenharmony_ci| grid-auto-flow | string | - | No| How grid items are laid out automatically. Available values are as follows:<br>- **row**: Elements are filled row by row. When there is no horizontal space in a row, a new row is added.<br>- **column**: Elements are filled column by column. When there is no vertical space in a column, a new column is added.| 37e41f4b71Sopenharmony_ci| align-items | string | - | 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 flex container along the cross axis.<br>- **flex-start**: Items are aligned to the start of the cross axis.<br>- **flex-end**: Items are aligned to the end of the cross axis.<br>- **center**: Items are aligned in the center of the cross axis.<br>- **baseline**: In a vertical layout, items are aligned to the start of the cross axis, which means that this value is equivalent of **flex-start**. In a horizontal layout, items are aligned with the text baseline if there is text involved, and aligned to the bottom otherwise.| 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci## Events 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ciThe [universal events](js-service-widget-common-events.md) are supported. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci## Example 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci1. Flex style 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci ```html 50e41f4b71Sopenharmony_ci <!-- xxx.hml --> 51e41f4b71Sopenharmony_ci <div class="container"> 52e41f4b71Sopenharmony_ci <div class="flex-box"> 53e41f4b71Sopenharmony_ci <div class="flex-item color-primary"></div> 54e41f4b71Sopenharmony_ci <div class="flex-item color-warning"></div> 55e41f4b71Sopenharmony_ci <div class="flex-item color-success"></div> 56e41f4b71Sopenharmony_ci </div> 57e41f4b71Sopenharmony_ci </div> 58e41f4b71Sopenharmony_ci ``` 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci ```css 62e41f4b71Sopenharmony_ci /* xxx.css */ 63e41f4b71Sopenharmony_ci .container { 64e41f4b71Sopenharmony_ci flex-direction: column; 65e41f4b71Sopenharmony_ci justify-content: center; 66e41f4b71Sopenharmony_ci align-items: center; 67e41f4b71Sopenharmony_ci width: 454px; 68e41f4b71Sopenharmony_ci height: 454px; 69e41f4b71Sopenharmony_ci } 70e41f4b71Sopenharmony_ci .flex-box { 71e41f4b71Sopenharmony_ci justify-content: space-around; 72e41f4b71Sopenharmony_ci align-items: center; 73e41f4b71Sopenharmony_ci width: 400px; 74e41f4b71Sopenharmony_ci height: 140px; 75e41f4b71Sopenharmony_ci background-color: #ffffff; 76e41f4b71Sopenharmony_ci } 77e41f4b71Sopenharmony_ci .flex-item { 78e41f4b71Sopenharmony_ci width: 120px; 79e41f4b71Sopenharmony_ci height: 120px; 80e41f4b71Sopenharmony_ci border-radius: 16px; 81e41f4b71Sopenharmony_ci } 82e41f4b71Sopenharmony_ci .color-primary { 83e41f4b71Sopenharmony_ci background-color: #007dff; 84e41f4b71Sopenharmony_ci } 85e41f4b71Sopenharmony_ci .color-warning { 86e41f4b71Sopenharmony_ci background-color: #ff7500; 87e41f4b71Sopenharmony_ci } 88e41f4b71Sopenharmony_ci .color-success { 89e41f4b71Sopenharmony_ci background-color: #41ba41; 90e41f4b71Sopenharmony_ci } 91e41f4b71Sopenharmony_ci ``` 92e41f4b71Sopenharmony_ci **2 x 4 widget** 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci  95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci2. Flex wrap style 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci ```html 99e41f4b71Sopenharmony_ci <!-- xxx.hml --> 100e41f4b71Sopenharmony_ci <div class="container"> 101e41f4b71Sopenharmony_ci <div class="flex-box"> 102e41f4b71Sopenharmony_ci <div class="flex-item color-primary"></div> 103e41f4b71Sopenharmony_ci <div class="flex-item color-warning"></div> 104e41f4b71Sopenharmony_ci <div class="flex-item color-success"></div> 105e41f4b71Sopenharmony_ci </div> 106e41f4b71Sopenharmony_ci </div> 107e41f4b71Sopenharmony_ci ``` 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci ```css 111e41f4b71Sopenharmony_ci /* xxx.css */ 112e41f4b71Sopenharmony_ci .container { 113e41f4b71Sopenharmony_ci flex-direction: column; 114e41f4b71Sopenharmony_ci justify-content: center; 115e41f4b71Sopenharmony_ci align-items: center; 116e41f4b71Sopenharmony_ci width: 454px; 117e41f4b71Sopenharmony_ci height: 454px; 118e41f4b71Sopenharmony_ci } 119e41f4b71Sopenharmony_ci .flex-box { 120e41f4b71Sopenharmony_ci justify-content: space-around; 121e41f4b71Sopenharmony_ci align-items: center; 122e41f4b71Sopenharmony_ci flex-wrap: wrap; 123e41f4b71Sopenharmony_ci width: 300px; 124e41f4b71Sopenharmony_ci height: 250px; 125e41f4b71Sopenharmony_ci background-color: #ffffff; 126e41f4b71Sopenharmony_ci } 127e41f4b71Sopenharmony_ci .flex-item { 128e41f4b71Sopenharmony_ci width: 120px; 129e41f4b71Sopenharmony_ci height: 120px; 130e41f4b71Sopenharmony_ci border-radius: 16px; 131e41f4b71Sopenharmony_ci } 132e41f4b71Sopenharmony_ci .color-primary { 133e41f4b71Sopenharmony_ci background-color: #007dff; 134e41f4b71Sopenharmony_ci } 135e41f4b71Sopenharmony_ci .color-warning { 136e41f4b71Sopenharmony_ci background-color: #ff7500; 137e41f4b71Sopenharmony_ci } 138e41f4b71Sopenharmony_ci .color-success { 139e41f4b71Sopenharmony_ci background-color: #41ba41; 140e41f4b71Sopenharmony_ci } 141e41f4b71Sopenharmony_ci ``` 142e41f4b71Sopenharmony_ci **4 x 4 widget** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci  145