Skip to content

Flex Flexible Layout Component

Flex provides spacing for block-level elements without adding a wrapper element itself. It is suitable for arranging child elements in vertical or horizontal directions, and offers greater flexibility and control.

📌Platform Compatibility Notes

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯Basic Usage Example

html
<!-- Global usage -->
<hy-flex>
    <hy-button size="small">Submit</hy-button>
    <hy-button size="small" type="success">Review</hy-button>
    <hy-button size="small" type="error">Delete</hy-button>
</hy-flex>

Setting Alignment

  • Set the alignment along the main axis via justify
  • Set the alignment along the cross axis via align
html
<hy-flex justify="center" align="center">
    <hy-button size="small">Button</hy-button>
</hy-flex>

Setting Spacing

  • Control the spacing between elements via gap; the first value of the array is the horizontal spacing, and the second is the vertical spacing
html
<hy-flex :gap="10">
    <template v-for="item in 4">
        <hy-button size="small">Button</hy-button>
    </template>
</hy-flex>

Automatic Wrapping

  • Enable automatic wrapping via wrap
html
<hy-flex wrap="wrap" :gap="[15, 20]">
    <template v-for="item in 10">
        <hy-button size="small">Button</hy-button>
    </template>
</hy-flex>

API

Flex Props

ParameterDescriptionTypeDefault
verticalWhether the flex main axis direction is vertical, using flex-direction: columnbooleanfalse
wrapSets whether elements are displayed in a single line or multiple linesbooleannowrap
justifySets the alignment of elements along the main axis[1]stringflex-start
alignSets the alignment of elements along the cross axis[2]stringflex-start
flexflex CSS shorthand propertystringinitial
gapSets the gap between grids; the default unit for numeric values is pxstring|number|number[]0
basisControls the initial size of child elements along the main axisstringauto
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-
03:29

  1. flex-start: left-aligned; center: centered; flex-end: right-aligned; space-between: justified, with equal spacing between items; space-around: equal spacing on both sides of each item, with the spacing between items being twice the spacing between items and the container edges; space-evenly: all spacing completely equal; ↩︎

  2. flex-start: top-aligned; center: centered; flex-end: bottom-aligned; stretch: stretched to fill the container; baseline: baseline-aligned; ↩︎