Basic Layouts
Vaadin features two basic layout components: Vertical Layout and Horizontal Layout. As their names suggest, they render their contents vertically and horizontally, respectively. Components are shown in the order they are added to either layout.
Vertical Layout
Vertical Layout places components top-to-bottom in a column. By default, it has 100% width and undefined height, meaning its width is constrained by its parent component and its height is determined by the components it contains.
Components in a Vertical Layout can be aligned both vertically and horizontally.
Vertical Alignment
You can position components at the top, middle, or bottom. Alternatively, you can position components by specifying how a layout’s excess space (if any) is distributed between them.
Value | Description |
---|---|
| Positions items at the top. |
| Vertically centers items. |
| Positions items at the bottom. |
| Available space is distributed evenly between items. No space is added before the first item, or after the last. |
| Available space is distributed evenly between items. The space before the first item, and after the last, is half of that between items. |
| Available space is distributed evenly between items. The space before the first item, between items and after the last item is the same. |
Horizontal Alignment
Components in a Vertical Layout can be left-aligned (default), centered, right-aligned or stretched horizontally.
Value | Description |
---|---|
| Left-aligns (LTR) or right-aligns (RTL) items |
| Horizontally centers items |
| Right-aligns (LTR) or left-aligns (RTL) items |
| Stretches items with undefined width horizontally |
It is also possible to horizontally align individual components, overriding the alignment set by the parent layout.
Horizontal Layout
Horizontal Layout places components side-by-side in a row. By default, it has undefined width and height, meaning its size is determined by the components it contains.
Like Vertical Layout, Horizontal Layout enables both vertical and horizontal alignment of components.
Vertical Alignment
You can position components at the top, middle, or bottom. Items can alternatively be made to stretch vertically or positioned along the layout’s text baseline.
Value | Description |
---|---|
| Stretches items with undefined height horizontally |
| Positions items at the top of the layout |
| Vertically centers items |
| Positions items at the bottom of the layout |
| Position items along the layout’s (text) baseline. |
It is also possible to vertically align individual components, overriding the alignment set by the parent layout.
Horizontal Alignment
Components in a Horizontal Layout can be left-aligned, centered or right-aligned. Alternatively, you can position components by specifying how a layout’s excess space is distributed between them.
Value | Description |
---|---|
| Left-aligns (LTR) or right-aligns (RTL) items |
| Right-aligns (LTR) or left-aligns (RTL) items |
| Horizontally centers items |
| Available space is distributed evenly between items. No space is added before the first item, or after the last. |
| Available space is distributed evenly between items. The space before the first item, and after the last, is half of that between items. |
| Available space is distributed evenly between items. The space before the first item, between items and after the last item is the same. |
Spacing
Spacing is used to create space between components in the same layout. Spacing can help prevent misclicks and distinguish content areas.
Warning
|
CAUTION: Combining spacing and alignment
Vertical Layout’s vertical alignment and Horizontal Layout’s horizontal alignment might not work properly when spacing is enabled.
If your layout requires both, consider disabling spacing and handling the alignment using CSS.
|
Five different spacing theme variants are available:
Theme variant | Usage recommendations |
---|---|
| Extra small space between items |
| Small space between items |
| Medium space between items |
| Large space between items |
| Extra large space between items |
Padding
Padding is the space between a layout’s outer border and its content. Padding can help distinguish a layout’s content from its surroundings. Padding is applied using the padding theme variant.
Expanding Items
Components can be made to expand and take up any excess space a layout may have.
When multiple components expand, they do so relative to each other. For example, two items with expand ratios of 2 and 1, will result in the first item taking up twice as much of the available space as the second item.
2482A61D-676F-4486-8450-B558D4FD49DD