1e41f4b71Sopenharmony_ci# grid-col 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe **\<grid-col>** is the child component of the **\<grid-row>** container. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Required Permissions 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciNone 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## Child Components 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciSupported 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## Attributes 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 24e41f4b71Sopenharmony_ci| ------ | -------------- | ---- | ---- | ---------------------------------------- | 25e41f4b71Sopenharmony_ci| xs | number\|object | - | No | Number of columns occupied by this item and its offset when **sizetype** is **xs**. If you set the value of the number type, you only set the number of columns. You can set a value of the object type for both the number of occupied columns and the offset, for example, **{"span": 1, "offset": 0}**. | 26e41f4b71Sopenharmony_ci| sm | number\|object | - | No | Number of columns occupied by this item and its offset when **sizetype** is **sm**. If you set the value of the number type, you only set the number of columns. You can set a value of the object type for both the number of occupied columns and the offset, for example, **{"span": 1, "offset": 0}**. | 27e41f4b71Sopenharmony_ci| md | number\|object | - | No | Number of columns occupied by this item and its offset when **sizetype** is **md**. If you set the value of the number type, you only set the number of columns. You can set a value of the object type for both the number of occupied columns and the offset, for example, **{"span": 1, "offset": 0}**. | 28e41f4b71Sopenharmony_ci| lg | number\|object | - | No | Number of columns occupied by this item and its offset when **sizetype** is **lg**. If you set the value of the number type, you only set the number of columns. You can set a value of the object type for both the number of occupied columns and the offset, for example, **{"span": 1, "offset": 0}**. | 29e41f4b71Sopenharmony_ci| span | number | 1 | No | Default number of columns occupied by the item when no breakpoint is set. | 30e41f4b71Sopenharmony_ci| offset | number | 0 | No | Default number of offset columns in the container layout direction when **"offset"** is not set for a specific **sizetype**. | 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci## Styles 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-components-common-styles.md), the following styles are supported. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 38e41f4b71Sopenharmony_ci| ----------------------------- | -------------- | ---------- | ---- | ---------------------------------------- | 39e41f4b71Sopenharmony_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.| 40e41f4b71Sopenharmony_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**: Items are displayed on a single axis.<br>- **wrap**: Items are displayed on multiple axes.| 41e41f4b71Sopenharmony_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 towards the start row.<br>- **flex-end**: Items are packed towards the end row.<br>- **center**: Items are centered along the row.<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.| 42e41f4b71Sopenharmony_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 in the cross axis direction.<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.| 43e41f4b71Sopenharmony_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 towards the start 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 towards the end 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 towards the center of the container. 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, and the spacing between two adjacent lines 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.| 44e41f4b71Sopenharmony_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>- **grid**: grid layout.<br>- **none**: The box is disabled.| 45e41f4b71Sopenharmony_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>- **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.| 46e41f4b71Sopenharmony_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**.| 47e41f4b71Sopenharmony_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**.| 48e41f4b71Sopenharmony_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**.| 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci> **NOTE** 51e41f4b71Sopenharmony_ci> 52e41f4b71Sopenharmony_ci> Width-related styles are not supported. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci## Events 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciThe [universal events](js-components-common-events.md) are supported. 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci## Methods 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciThe [universal methods](js-components-common-methods.md) are supported. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## Example 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci```html 68e41f4b71Sopenharmony_ci<!-- index.hml --> 69e41f4b71Sopenharmony_ci<div class="container"> 70e41f4b71Sopenharmony_ci <grid-container id="mygrid" columns="5" gutter="20px" style="background-color: pink;"> 71e41f4b71Sopenharmony_ci <grid-row style="height:400px;justify-content:space-around;"> 72e41f4b71Sopenharmony_ci <grid-col span="2"> 73e41f4b71Sopenharmony_ci <div style="align-items: center;justify-content: center;height: 100%;width: 100%;"> 74e41f4b71Sopenharmony_ci <text style="color: dodgerblue;" onclick="getCol">Element text</text> 75e41f4b71Sopenharmony_ci </div> 76e41f4b71Sopenharmony_ci </grid-col> 77e41f4b71Sopenharmony_ci <grid-col span="3" style="background-color:orange;"> 78e41f4b71Sopenharmony_ci <div style="width: 100%;height: 100%;padding: 20px;align-items: center;"> 79e41f4b71Sopenharmony_ci <text onclick="getColWidth">Element text</text> 80e41f4b71Sopenharmony_ci </div> 81e41f4b71Sopenharmony_ci </grid-col> 82e41f4b71Sopenharmony_ci </grid-row> 83e41f4b71Sopenharmony_ci </grid-container> 84e41f4b71Sopenharmony_ci</div> 85e41f4b71Sopenharmony_ci``` 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci```css 88e41f4b71Sopenharmony_ci/* index.css */ 89e41f4b71Sopenharmony_ci.container { 90e41f4b71Sopenharmony_ci flex-direction: column; 91e41f4b71Sopenharmony_ci padding-top: 80px; 92e41f4b71Sopenharmony_ci} 93e41f4b71Sopenharmony_ci``` 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci```js 96e41f4b71Sopenharmony_ci// index.js 97e41f4b71Sopenharmony_ciimport prompt from '@system.prompt'; 98e41f4b71Sopenharmony_ciexport default { 99e41f4b71Sopenharmony_ci getCol(e) { 100e41f4b71Sopenharmony_ci this.$element('mygrid').getColumns(function (result) { 101e41f4b71Sopenharmony_ci prompt.showToast({ 102e41f4b71Sopenharmony_ci message: e.target.id + ' result = ' + result, 103e41f4b71Sopenharmony_ci duration: 3000, 104e41f4b71Sopenharmony_ci }); 105e41f4b71Sopenharmony_ci }) 106e41f4b71Sopenharmony_ci }, 107e41f4b71Sopenharmony_ci getColWidth(e) { 108e41f4b71Sopenharmony_ci this.$element('mygrid').getColumnWidth(function (result) { 109e41f4b71Sopenharmony_ci prompt.showToast({ 110e41f4b71Sopenharmony_ci message: e.target.id + ' result = ' + result, 111e41f4b71Sopenharmony_ci duration: 3000, 112e41f4b71Sopenharmony_ci }); 113e41f4b71Sopenharmony_ci }) 114e41f4b71Sopenharmony_ci } 115e41f4b71Sopenharmony_ci} 116e41f4b71Sopenharmony_ci``` 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci 119