Grid
Description
The Grid component provides a flexible layout container that arranges its child components into a grid structure. It is used primarily for collections where items need to be aligned in rows and columns. You can define custom column and row sizes and adjust layout properties like gaps, alignment, and overflow.
Usage
Instantiate a Grid using the helper method from Tesserae.UI and specify the column sizes. Items are added using the Add method, and you can customize grid behavior using chaining methods.
Public Properties
- Background
- Get or set the background CSS property value.
- Margin
- Get or set the margin CSS property value.
- Padding
- Get or set the padding CSS property value.
- StylingContainer
- Gets the underlying HTMLElement used for styling.
- PropagateToStackItemParent
- Indicates if style changes should propagate to the parent in stack items (read-only via chaining methods).
API reference
public class Grid : IContainer<Grid, IComponent>, IHasBackgroundColor, IHasMarginPadding, ISpecialCaseStylingA CSS-Grid container with explicit row and column tracks, gap and alignment, for two-dimensional layouts.
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.
Methods
public Grid Columns(params UnitSize[] columns)Defines the columns of the grid (track sizes).
public static void SetGridColumn(IComponent component, int start, int end)Needs to be called before the component is added to the Grid.
public static void SetGridRow(IComponent component, int start, int end)Needs to be called before the component is added to the Grid.
public Grid AlignItems(ItemAlign align)Sets the align-items css property for this stack
Parameters
- align
public Grid AlignContent(ItemAlign align)Sets the align-items css property for this stack
Parameters
- align
public Grid JustifyContent(ItemJustify justify)Sets the justify-content css property for this stack
Parameters
- justify
public Grid JustifyItems(ItemJustify justify)Sets the justify-content css property for this stack
Parameters
- justify
public Grid AlignItemsCenter()Sets the align-items css property for this grid to 'center'
Parameters
- align
public Grid OverflowHidden()Hides any content that overflows the component's bounds.
public Grid ColumnGap(UnitSize gapSize)Sets the gap between columns of the grid.
public Grid AutoRows(UnitSize autoRowValue)Sets the auto-generated row size of the grid.
public Grid AutoColumn(UnitSize autoColumnValue)Sets the auto-generated column size of the grid.
public Grid RemovePropagation()Removes the given propagation from the component.
public Grid NoDefaultMargin()Removes / disables the default margin on the component.
public void Replace(IComponent newComponent, IComponent oldComponent)Replaces an existing item with a new one.
Samples
Basic Grid Sample
This sample demonstrates creating a simple grid with three columns, setting a gap between items, and adding multiple buttons.
Auto-Sizing Responsive Grid
This sample uses CSS Grid's auto-fit plus minmax so the number of columns adapts to the available width — narrow viewports collapse to a single column, wide viewports show several.
Row Gaps, Column Gaps and Alignment
RowGap and ColumnGap set the spacing in each direction independently. AlignItems and JustifyItems control how cells with extra space lay their content out.
Spans and Manual Cell Placement
Components can occupy multiple rows or columns by using GridRow / GridColumn. This sample creates a 4-column layout where the first card is stretched across two rows and the second across two columns.
See Also
- Stack – Use in scenarios where vertical or horizontal stacking is required.
- Masonry – For alternative grid-based layouts with dynamic columns.
- VirtualizedList – For performance optimized long lists.