Class Container


public class Container extends StyledElement<Container>
A centered container with configurable maximum width for constraining page content.

Container provides a max-width constraint with automatic horizontal centering, commonly used to prevent content from stretching too wide on large screens. It includes predefined size presets matching common breakpoint conventions.

Size Presets:

Usage:


 // Default container (LG - 1024px)
 Container container = new Container();
 container.addElement(content);

 // Small container for narrow content
 Container narrow = new Container(Container.Size.SM);
 narrow.addElement(articleText);

 // Container with horizontal padding
 Container padded = new Container(Container.Size.XL);
 padded.setPaddingX("1rem");

 // Custom max-width
 Container custom = new Container("900px");
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • invalid reference
    Section
  • VStack
  • Constructor Details

    • Container

      public Container()
      Constructs a container with the default size (LG - 1024px).
    • Container

      public Container(Container.Size size)
      Constructs a container with the specified size preset.
      Parameters:
      size - the size preset
    • Container

      public Container(String maxWidth)
      Constructs a container with a custom maximum width.
      Parameters:
      maxWidth - the maximum width (e.g., "900px", "60rem", "80%")
  • Method Details

    • setSize

      public Container setSize(Container.Size size)
      Sets the container size using a preset.
      Parameters:
      size - the size preset
      Returns:
      this Container for method chaining
    • setPaddingX

      public Container setPaddingX(String padding)
      Sets horizontal padding (left and right) for the container.

      This is useful for adding gutters to prevent content from touching the edges of the viewport on smaller screens.

      Parameters:
      padding - the padding value (e.g., "1rem", "16px")
      Returns:
      this Container for method chaining
    • setPaddingX

      public Container setPaddingX(int padding)
      Sets horizontal padding (left and right) for the container in pixels.
      Parameters:
      padding - the padding in pixels
      Returns:
      this Container for method chaining
    • setPaddingY

      public Container setPaddingY(String padding)
      Sets vertical padding (top and bottom) for the container.
      Parameters:
      padding - the padding value (e.g., "2rem", "32px")
      Returns:
      this Container for method chaining
    • setPaddingY

      public Container setPaddingY(int padding)
      Sets vertical padding (top and bottom) for the container in pixels.
      Parameters:
      padding - the padding in pixels
      Returns:
      this Container for method chaining