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
public class Masonry : IContainer<Masonry, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStylingA masonry (Pinterest-style) layout that flows items of varying heights into columns of equal width.
Constructors
Properties
public string Background { get ; set ; }Gets or sets the CSS background of the component.
public string Margin { get ; set ; }Gets or sets the CSS margin of the component.
public string Padding { get ; set ; }Gets or sets the CSS padding of the component.
public HTMLElement StylingContainerGets or sets the styling container.
Methods
public void Replace(IComponent newComponent, IComponent oldComponent)Replaces an existing item with a new one.
public void Remove(IComponent component)Removes the given item from the component.
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.