package com.vaadin.demo.component.verticallayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
@Route("vertical-layout-spacing")
public class VerticalLayoutSpacing extends Div {
public VerticalLayoutSpacing() {
HorizontalLayout parent = new HorizontalLayout();
parent.getStyle().setBorder("0");
add(parent);
Div wrapper = new Div();
wrapper.setWidthFull();
wrapper.add(new Paragraph("Vertical layout without spacing:"));
parent.add(wrapper);
// tag::snippet[]
// VerticalLayout has spacing enabled by default, use setSpacing to
// disable it
VerticalLayout layoutWithoutSpacing = new VerticalLayout();
layoutWithoutSpacing.setSpacing(false);
// end::snippet[]
layoutWithoutSpacing.setAlignItems(FlexComponent.Alignment.STRETCH);
Div item1 = new Div("Item 1");
item1.setClassName("example-item");
Div item2 = new Div("Item 2");
item2.setClassName("example-item");
Div item3 = new Div("Item 3");
item3.setClassName("example-item");
layoutWithoutSpacing.add(item1, item2, item3);
wrapper.add(layoutWithoutSpacing);
wrapper = new Div();
wrapper.setWidthFull();
wrapper.add(new Paragraph("Vertical layout with spacing:"));
parent.add(wrapper);
VerticalLayout layoutWithSpacing = new VerticalLayout();
layoutWithSpacing.setAlignItems(FlexComponent.Alignment.STRETCH);
Div spacingItem1 = new Div("Item 1");
spacingItem1.setClassName("example-item");
Div spacingItem2 = new Div("Item 2");
spacingItem2.setClassName("example-item");
Div spacingItem3 = new Div("Item 3");
spacingItem3.setClassName("example-item");
layoutWithSpacing.add(spacingItem1, spacingItem2, spacingItem3);
wrapper.add(layoutWithSpacing);
setClassName("basic-layouts-example");
}
}
Padding is the space allocated between the content in a layout and the outer border. This should not be confused with Margin, which is explained in the next section.
Padding can help distinguish the content in a layout from its surrounding. Padding is applied using the padding style variant.
package com.vaadin.demo.component.verticallayout;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
@Route("vertical-layout-padding")
public class VerticalLayoutPadding extends Div {
public VerticalLayoutPadding() {
HorizontalLayout parent = new HorizontalLayout();
parent.getStyle().setBorder("0");
add(parent);
Div wrapper = new Div();
wrapper.setWidthFull();
wrapper.add(new Paragraph("Vertical layout without padding:"));
parent.add(wrapper);
// tag::snippet[]
// VerticalLayout has padding enabled by default, use setPadding to
// disable it
VerticalLayout layoutWithoutPadding = new VerticalLayout();
layoutWithoutPadding.setPadding(false);
// end::snippet[]
layoutWithoutPadding.setAlignItems(FlexComponent.Alignment.STRETCH);
Div item1 = new Div("Item 1");
item1.setClassName("example-item");
Div item2 = new Div("Item 2");
item2.setClassName("example-item");
Div item3 = new Div("Item 3");
item3.setClassName("example-item");
layoutWithoutPadding.add(item1, item2, item3);
wrapper.add(layoutWithoutPadding);
wrapper = new Div();
wrapper.setWidthFull();
wrapper.add(new Paragraph("Vertical layout with padding:"));
parent.add(wrapper);
VerticalLayout layoutWithPadding = new VerticalLayout();
layoutWithPadding.setAlignItems(FlexComponent.Alignment.STRETCH);
Div paddingItem1 = new Div("Item 1");
paddingItem1.setClassName("example-item");
Div paddingItem2 = new Div("Item 2");
paddingItem2.setClassName("example-item");
Div paddingItem3 = new Div("Item 3");
paddingItem3.setClassName("example-item");
layoutWithPadding.add(paddingItem1, paddingItem2, paddingItem3);
wrapper.add(layoutWithPadding);
setClassName("basic-layouts-example");
}
}
By default, components in a layout either shrink or overflow when there isn’t enough vertical space. Enable wrapping to allow components to flow onto a new column when space runs out, preventing overflow.
The following style properties can be used in CSS stylesheets to customize the appearance of this component.
To apply values to these properties globally in your application UI, place them in a CSS block using the html {…} selector.
See Component Style Properties for more information on style properties.
Property
Supported by
--vaadin-vertical-layout-gap
Aura, Lumo
--vaadin-vertical-layout-padding
Aura, Lumo
--vaadin-vertical-layout-margin
Aura, Lumo
CSS Selectors
The following CSS selectors can be used in stylesheets to target the various parts and states of the component.
See the Styling documentation for more details on how to style components.