Masonry

Description

The Masonry component arranges its child components in a dynamic, grid-like layout where items are organized into columns of equal width. It is part of the Collections group and is ideal for displaying cards or items with variable height, much like a Pinterest-style layout. Use this component when you need a responsive, masonry-style grid that automatically lays out items in multiple columns with a configurable gutter.

Usage

Instantiate the Masonry component using the static helper methods provided by the Tesserae.UI class. Specify the number of columns and optional gutter space (in pixels) between items. The component automatically wraps each child in a container with styling adjustments.

Below is a minimal example demonstrating how to create a Masonry layout with several card components:

API reference

class

Masonry

public class Masonry : IContainer<Masonry, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling

A masonry (Pinterest-style) layout that flows items of varying heights into columns of equal width.

Namespace
Tesserae
Implements
IContainer<Masonry, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStyling

Constructors

NameDescription
MasonryInitializes a new instance of this class.
Constructor
Masonry
public Masonry(int columns, int gutter = 10)

Initializes a new instance of this class.

Properties

NameDescription
BackgroundGets or sets the CSS background of the component.
MarginGets or sets the CSS margin of the component.
PaddingGets or sets the CSS padding of the component.
StylingContainerGets or sets the styling container.
PropagateToStackItemParentGets or sets the propagate to stack item parent.
Property
Masonry.Background
public string Background { get ; set ; }

Gets or sets the CSS background of the component.

Property
Masonry.Margin
public string Margin { get ; set ; }

Gets or sets the CSS margin of the component.

Property
Masonry.Padding
public string Padding { get ; set ; }

Gets or sets the CSS padding of the component.

Property
Masonry.StylingContainer
public HTMLElement StylingContainer

Gets or sets the styling container.

Property
Masonry.PropagateToStackItemParent
public bool PropagateToStackItemParent

Gets or sets the propagate to stack item parent.

Methods

NameDescription
AddAdds the given item to the component.
ClearClears the component's current state.
ReplaceReplaces an existing item with a new one.
RemoveRemoves the given item from the component.
RenderRenders the component's root HTML element.
Method
Masonry.Add
public void Add(IComponent component)

Adds the given item to the component.

Method
Masonry.Clear
public virtual void Clear()

Clears the component's current state.

Method
Masonry.Replace
public void Replace(IComponent newComponent, IComponent oldComponent)

Replaces an existing item with a new one.

Method
Masonry.Remove
public void Remove(IComponent component)

Removes the given item from the component.

Method
Masonry.Render
public virtual HTMLElement Render()

Renders the component's root HTML element.

Samples

Masonry Layout with Dynamic Cards

In this sample, a Masonry layout is created with 4 columns. Cards with varying heights are dynamically generated and added to the layout.

See also

  • Stack – For general vertical or horizontal stacking of UI components.
  • Grid – For displaying items in a grid with fixed rows and columns.
© 2026 Curiosity. All rights reserved.