Ant Design Svelte

Flex

Flexible layout: direction, axes, spacing, translation and combination of components.

When to use

Flex arranges the immediate children of a row or column, aligns them, and sets their spacing. It is suitable for action bars, cards and areas with stretchable elements. Space is useful for individual elements with wrappers and dividers; Grid - for a proportional grid.

Flex creates one root container, without additional wrappers for each child. The content is transmitted through Svelte snippet children.

Axes, spacing and translation

orientation=horizontal/vertical specifies the direction and takes precedence over vertical. Without local configuration, vertical can be inherited from ConfigProvider.flex.

Problem Setting Example
Select row or column orientation, vertical Layout direction
Align immediate children justify, align Two-axis alignment
Set distances gap Spacing between elements
Allow multiple lines wrap Line wrapping
Distribute free width flex on child elements Free space distribution

justify acts along the main axis, align - along the transverse one. When moving from row to column, their meaning is preserved relative to the axes, so the screen direction changes. Explicit alignment values ​​make the result predictable.

gap accepts small/medium/large, px number or CSS string. Presets follow the general theme padding. wrap=true corresponds to wrap; nowrap and wrap-reverse are also available. Carrying requires available width and suitable child sizes.

Flex prop refers to the container itself as an element of the parent flexbox. To distribute its contents, set flex to the immediate children. Combination with components shows regular Card, Tag and Button without special adapters.

Root element and settings

component is the default div and can be a native tag or a Svelte component. Native container uses a semantic list; keep appropriate child tags, such as li for ul.

The native component receives children, class, style, dir and additional props. Pass them on to your real root. For bind:nativeElement, declare it $bindable nativeElement and bind it to the DOM via bind:this; without such forwarding ref Flex will remain undefined.

ConfigProvider.flex inherits class, style and vertical. The passed nested record replaces the parent one; local orientation/vertical and style take precedence. Explicit flex and custom gap are added after style. There are no separate semantic classNames/styles and no own named component design tokens.

A non-empty local prefixCls specifies the full CSS prefix. Without it, including when the line is empty, ConfigProvider.prefixCls with the suffix -flex is used, the default is ant-flex. The custom component receives the already resolved classes and must pass them to its root. Example ConfigProvider shows nested inheritance and independent adjacent scope.

Alignment and CSS order do not change the reading order and Tab. Maintain a meaningful sequence of interactive elements in the DOM. bind:nativeElement is available after mount and is cleared upon unmount.

Examples

1
2
3
4

Layout direction

Flex arranges immediate children into a row or column without creating a wrapper for each element.

One
Two
Three

Two-axis alignment

justify controls the main axis, align controls the cross axis. The height of the container leaves room for comparison.

Spacing between elements

Named intervals follow a theme; the number specifies the pixels. You can also pass a CSS string, such as 1rem.

Line breaks

wrap wraps elements when there is not enough width. Without wrapping, content can be scrolled within the display area.

Project documentation
Examples of componentsReady

One card combines release information and actions.

Combination with components

Nested Flex collects the contents of the Card: the main text is stretched, and the actions are transferred to a narrow screen.

1
2

Free space allocation

flex sets the behavior of a nested Flex as an element of the parent container. Here the free space is divided in a ratio of 1:2.

  • Development
  • Check
  • Publication

Native container

component selects the HTML tag. The list remains a real ul with immediate li; A React component cannot be passed.

Project activities

Saved review example with direction, interval and distribution of actions.

API

Themes of the ant.design live page are mapped to the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
BasicRow and column.
alignMain and transverse axles.
gapThematic and numerical intervals.
WrapTransfer and local scrolling.
Combination with componentsComposition of Card, Tag and Button.
Basic parameters Flex
PropertyDescriptionTypeDefault
prefixClsFull local CSS prefix. The empty string inherits the common prefix; ant-flex is used without configuration. The custom component receives the allowed classes.stringConfigProvider + -flex
orientationDirection; takes precedence over vertical.horizontal | verticalhorizontal
verticalColumn instead of row if orientation is not specified; without a local prop, ConfigProvider.flex.vertical is inherited.booleanfalse
wraptrue matches wrap. Without wrapping, wide content requires limiting or scrolling.boolean | wrap | nowrap | wrap-reverse—
justifyDistribution along the main axis.FlexJustifyCSS normal
alignAlignment along the transverse axis.FlexAlignstretch for column
gapTheme preset, CSS string or number in px.small | medium | large | string | number—
flexCSS flex container as an element of its parent.string | number—
componentNative HTML tag or custom Svelte component with forwarding root props.keyof HTMLElementTagNameMap | Component<Props>div
childrenChild elements without additional wrappers.Snippet—
styleCSS of the root container; explicit props flex and numeric/string gap are added after style.string—
nativeElementbind:nativeElement returns root; the custom component must pass a $bindable ref.HTMLElement—

Semantic DOM

Flex creates one container, div by default. children is rendered directly, so the CSS, focus, and semantics of the immediate children are preserved. component selects an HTML tag or Svelte component; bind:nativeElement returns the root after mount if the custom component passes a ref.

ConfigProvider.flex inherits class/style and vertical. A custom component must pass children, class/style and dir to its root; nativeElement needs $bindable ref. There are no separate classNames/styles. Local props specify defaults, direction is inherited from ConfigProvider.

Registration tokens

Flex does not have its own component tokens. small/medium/large use common paddingXS/padding/paddingLG and react to the section theme. Numeric and CSS spacing remain defined by the application.

Common tokens of the current topic
TokenCurrent value
padding16
paddingLG24
paddingXS8

FAQ

When do you need Space?

For individual elements with wrappers and separators. Flex manages immediate children via CSS flexbox.

Why justify and align are swapped in a column?

Their meaning is associated with the main and transverse axes. The main axis of the column is vertical.

Why doesn't the element stretch from flex?

Prop flex refers to the container itself. To stretch its contents, adjust the children and their parent alignment.

Why is there no nativeElement in your own component?

The native Svelte root must declare $bindable nativeElement and pass a reference to its DOM node.