• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Stack
2
3The **\<Stack>** component provides a stack container where child components are successively stacked and the latter one overwrites the previous one.
4
5>  **NOTE**
6>
7>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## Child Components
11
12Supported
13
14
15## APIs
16
17Stack(value?: { alignContent?: Alignment })
18
19Since API version 9, this API is supported in ArkTS widgets.
20
21**Parameters**
22
23| Name      | Type                                   | Mandatory| Description                                                   |
24| ------------ | ------------------------------------------- | ---- | ----------------------------------------------------------- |
25| alignContent | [Alignment](ts-appendix-enums.md#alignment) | No  | Alignment of child components in the container.<br>Default value: **Alignment.Center**|
26
27## Attributes
28
29In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
30
31| Name        | Type                                   | Description                                                        |
32| ------------ | ------------------------------------------- | ------------------------------------------------------------ |
33| alignContent | [Alignment](ts-appendix-enums.md#alignment) | Alignment of child components in the container.<br>Default value: **Alignment.Center**<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>When both this attribute and the universal attribute [align](ts-universal-attributes-location.md) are set, whichever is set last takes effect.|
34
35
36## Example
37
38```ts
39// xxx.ets
40@Entry
41@Component
42struct StackExample {
43  build() {
44    Stack({ alignContent: Alignment.Bottom }) {
45      Text('First child, show in bottom').width('90%').height('100%').backgroundColor(0xd2cab3).align(Alignment.Top)
46      Text('Second child, show in top').width('70%').height('60%').backgroundColor(0xc1cbac).align(Alignment.Top)
47    }.width('100%').height(150).margin({ top: 5 })
48  }
49}
50```
51
52![en-us_image_0000001219982699](figures/en-us_image_0000001219982699.PNG)
53