Grid
Description
A component to display a grid
The Grid component provides a powerful layout system based on CSS Grid. It allows you to define columns, rows, and gaps between items.
Items within a Grid can be explicitly positioned or stretched across multiple tracks, offering full control over complex 2D layouts.
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
Fixed and Flexible Columns
This grid uses two flexible columns (1fr) and one fixed column (200px). The first item is stretched across all columns.
Responsive Auto-fit Grid
This grid automatically adjusts the number of columns based on the available width (min 200px per item).