Skip to content

Import

import { Flex } from '@dnb/eufemia'

Description

Flex.Item is a building block for CSS flexbox based layout of contents and components. Should be used in combination with Flex.Container.

import { Flex } from '@dnb/eufemia'
render(
<Flex.Container>
<Flex.Item>content</Flex.Item>
</Flex.Container>,
)

Size adjustment

You can provide a size property with a number from 1 to 12 (can be changed in Flex.Container with the sizeCount property).

The number will be used to set the item size (a part of the container). It set a percentage unit and apply it on the item via CSS. When the container is tilled to 100%, the remaining items will wrap to a new row.

The number 6 results in 50%, while 12 results in 100%.

uses 50% in width
uses 50% in width
Code Editor
<Flex.Container>
  <Flex.Item size={6}>uses 50% in width</Flex.Item>
  <Flex.Item size={6}>uses 50% in width</Flex.Item>
</Flex.Container>

Responsive size

You can also make sizes respond to media queries.

For doing so, provide a size property with an object containing Media Query types. Each media size should contain number, like mentioned above.

Code Editor
<Flex.Container>
  <Flex.Item
    size={{
      small: 12,
      large: 6,
    }}
  >
    uses 50% or 100% based on the screen size
  </Flex.Item>
  <Flex.Item
    size={{
      small: 12,
      large: 6,
    }}
  >
    uses 50% or 100% based on the screen size
  </Flex.Item>
</Flex.Container>

You need to ensure that flex-wrap: wrap is set, so the remaining items wrap to a new row when needed. This is enabled by default in the Flex.Container.

Demo

FlexItem
FlexItem
Code Editor
<Flex.Container>
  <Flex.Item>
    <TestElement>FlexItem</TestElement>
  </Flex.Item>
  <Flex.Item>
    <TestElement>FlexItem</TestElement>
  </Flex.Item>
</Flex.Container>

Basic size usage

With the default sizeCount of 12 parts.

FlexItem (8)
FlexItem (4)
FlexItem (small: 8, medium: 4)
FlexItem (small: 4, medium: 8)

Advanced size usage

The following example has a customized amount of 4 parts (sizeCount) as well as custom breakpoints and media queries.

FlexItem
FlexItem
FlexItem
FlexItem