** container whose **display** style is set to **grid**.|
| 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 **\
** container whose **display** style is set to **grid**.|
| grid-auto-flow
5+ | string | - | No | How grid items are laid out automatically. Available values are as follows:
- **row**: Elements are filled row by row. When there is no horizontal space in a row, a new row is added.
- **column**: Elements are filled column by column. When there is no vertical space in a column, a new column is added.|
| overflow
6+ | string | visible | No | Display mode when the content exceeds the container size. Available values are as follows:
- **visible**: Displays the excess content outside the container.
- **hidden**: Truncates the excess content.
- **scroll**: Scrolls the content vertically, with a scrollbar provided.
**scroll** works for elements whose size is fixed. By default, the scrolling direction is the same as the container direction.|
| align-items
6+ | string | - | No | How items are aligned along the cross axis in a flex container. Available values are as follows:
- **stretch**: Items are stretched to the same height or width as the flex container along the cross axis.
- **flex-start**: Items are aligned to the start of the cross axis.
- **flex-end**: Items are aligned to the end of the cross axis.
- **center**: Items are aligned in the center of the cross axis.
- **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.|
| scrollbar-color
6+ | <color> | - | No | Color of the scrollbar. |
| scrollbar-width
6+ | <length> | - | No | Width of the scrollbar. |
| overscroll-effect
6+ | string | - | No | How the scrollbar behaves when it reaches the edge of the scrolling area. Available values are as follows:
- **spring**: Similar to the physical dynamic effect of a spring. When the scrollbar reaches the edge, it can continue to scroll for a distance based on the initial speed or a touch event. It rebounds after being released.
- **fade**: Similar to the physical dynamic effect of fade. When the scrollbar reaches the edge, a wave shape fades. The fade changes according to the speed and scrolling distance.
- **none**: No effect when the scrollbar reaches the edge.|
## Events
In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.
| Name | Parameter | Description |
| ------------------------ | ---- | ---------------------------------------- |
| reachstart
6+ | - | Triggered when the page scrolls to the beginning. This event is triggered only when **flex-direction** is **row**.|
| reachend
6+ | - | Triggered when the page scrolls to the end. This event is triggered only when **flex-direction** is **row**.|
| reachtop
6+ | - | Triggered when the page scrolls to the top. This event is triggered only when **flex-direction** is **column**.|
| reachbottom
6+ | - | Triggered when the page scrolls to the bottom. This event is triggered only when **flex-direction** is **column**.|
## Methods
In addition to the [universal methods](js-components-common-methods.md), the following methods are supported.
| Name | Parameter | Return Value | Description |
| ---------------------------- | ----------- | ------------ | --------------------------------------- |
| getScrollOffset
6+ | - | ScrollOffset | Obtains the scrolling offset of the element content.
To use this method, **overflow** must be set to **scroll**.|
| scrollBy
6+ | ScrollParam | - | Sets the scrolling offset of the element content.
To use this method, **overflow** must be set to **scroll**.|
**Table 1** ScrollOffset
6+
| Name | Type | Description |
| ---- | ------ | --------------- |
| x | number | Offset in the x-axis direction, in px.|
| y | number | Offset in the y-axis direction, in px.|
**Table 2** ScrollParam
6+
| Name | Type | Description |
| ------ | ------- | ---------------- |
| dx | number | Offset for scrolling in the horizontal direction, in px.|
| dy | number | Offset for scrolling in the vertical direction, in px.|
| smooth | boolean | Whether to perform smooth processing. |
## Example
1. Flex style
```html
```
```css
/* xxx.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width: 454px;
height: 454px;
}
.flex-box {
justify-content: space-around;
align-items: center;
width: 400px;
height: 140px;
background-color: #ffffff;
}
.flex-item {
width: 120px;
height: 120px;
border-radius: 16px;
}
.color-primary {
background-color: #007dff;
}
.color-warning {
background-color: #ff7500;
}
.color-success {
background-color: #41ba41;
}
```
![en-us_image_0000001127285076](figures/en-us_image_0000001127285076.png)
2. Flex wrap style
```html
```
```css
/* xxx.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width: 454px;
height: 454px;
}
.flex-box {
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
width: 300px;
height: 250px;
background-color: #ffffff;
}
.flex-item {
width: 120px;
height: 120px;
border-radius: 16px;
}
.color-primary {
background-color: #007dff;
}
.color-warning {
background-color: #ff7500;
}
.color-success {
background-color: #41ba41;
}
```
![22](figures/22.png)
3. Grid style
```html
```
```css
/* xxx.css */
.common {
width: 400px;
height: 400px;
background-color: #ffffff;
align-items: center;
justify-content: center;
margin: 24px;
}
.grid-parent {
display: grid;
grid-template-columns: 35% 35%;
grid-columns-gap: 24px;
grid-rows-gap: 24px;
grid-template-rows: 35% 35%;
}
.grid-child {
width: 100%;
height: 100%;
border-radius: 8px;
}
.grid-left-top {
grid-row-start: 0;
grid-column-start: 0;
grid-row-end: 0;
grid-column-end: 0;
background-color: #3f56ea;
}
.grid-left-bottom {
grid-row-start: 1;
grid-column-start: 0;
grid-row-end: 1;
grid-column-end: 0;
background-color: #00aaee;
}
.grid-right-top {
grid-row-start: 0;
grid-column-start: 1;
grid-row-end: 0;
grid-column-end: 1;
background-color: #00bfc9;
}
.grid-right-bottom {
grid-row-start: 1;
grid-column-start: 1;
grid-row-end: 1;
grid-column-end: 1;
background-color: #47cc47;
}
```
![11](figures/11.png)
4. Dragging
7+
```html
```
```css
/* xxx.css */
.container {
flex-direction: column;
width: 100%;
height: 100%;
}
.content {
width: 200px;
height: 200px;
background-color: red;
}
```
```js
// xxx.js
import promptAction from '@ohos.promptAction';
export default {
data:{
left:0,
top:0,
},
dragstart(e){
prompt.showToast({
message: 'Start to be dragged'
})
},
drag(e){
this.left = e.globalX;
this.top = e.globalY;
},
dragend(e){
promptAction.showToast({
message: 'End Drag'
})
}
}
```
![9](figures/9.gif)
```html
```
```css
/* xxx.css */
.container {
flex-direction: column;
width: 100%;
position: relative;
max-width: 100%;
}
.content{
width: 200px;
height: 200px;
background-color: red;
position: absolute;
}
```
```js
// xxx.js
import promptAction from '@ohos.promptAction';
export default {
data:{
left:0,
top:0,
},
drag(e){
this.left = e.globalX;
this.top = e.globalY;
},
dragenter(e){
promptAction.showToast({
message: 'enter'
})
},
dragover(e){
promptAction.showToast({
message: 'over'
})
},
dragleave(e){
promptAction.showToast({
message: 'leave'
})
},
drop(e){
promptAction.showToast({
message: 'drop'
})
}
}
```
![6](figures/6.gif)
5. Pinching
7+
```html
```
```css
/* xxx.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
width: 454px;
height: 454px;
}
.content {
width: 400px;
height: 400px;
background-color: aqua;
margin: 30px;
}
```
```js
// xxx.js
import promptAction from '@ohos.promptAction';
export default {
pinchstart(e){
promptAction.showToast({
message: 'pinchstart!!!'
})
},
pinchupdate(e){
promptAction.showToast({
message: 'Two-finger pinch update'
})
},
pinchend(e){
promptAction.showToast({
message: 'Finished with two fingers pinching'
})
},
pinchcancel(e){
promptAction.showToast({
message: 'Finger pinching is interrupted'
})
}
}
```
![5](figures/5.gif)