Vitus Labs
Coolgrid

Row

Flex-wrap row container with gap compensation and alignment.

Row is a flex container that holds Columns. It handles gap compensation via negative margins and provides horizontal alignment.

Props

PropTypeDefaultDescription
childrenReactNodeColumn content
componentComponentType'div'Custom row element
cssExtraStylesExtra CSS (overrides cascaded rowCss)
contentAlignXContentAlignXHorizontal alignment of columns
columnsValueTypeInheritedTotal columns
sizeValueTypeInheritedDefault column size (cascades to Cols)
gapValueTypeInheritedSpace between columns
paddingValueTypeInheritedColumn padding (cascades)
gutterValueTypeInheritedSpace between this and adjacent rows
colCssExtraStylesInheritedCSS for child columns (cascades)
colComponentComponentTypeInheritedCustom Col component (cascades)

Styling

Row renders as a flex-wrap container:

display: flex;
flex-wrap: wrap;
flex-direction: row;
align-self: stretch;
box-sizing: border-box;

Gap Compensation

Row applies negative margins to offset column spacing:

spacingX = (gap / 2) * -1         // Horizontal: negative to offset column margins
spacingY = gutter ? gutter - gap/2 : gap/2  // Vertical: accounts for inter-row spacing
margin: ${spacingY}px ${spacingX}px;

This creates the classic CSS grid pattern where columns have consistent gaps while Row edges align with the Container.

Column Alignment

<Row contentAlignX="center">
  <Col size={4}>Centered content</Col>
</Row>

<Row contentAlignX="spaceBetween">
  <Col size={3}>Left</Col>
  <Col size={3}>Right</Col>
</Row>

<Row contentAlignX="spaceAround">
  <Col size={2}>A</Col>
  <Col size={2}>B</Col>
  <Col size={2}>C</Col>
</Row>

ContentAlignX Values

ValueCSSDescription
leftflex-startAlign columns to start
centercenterCenter columns
rightflex-endAlign columns to end
spaceBetweenspace-betweenEqual space between columns
spaceAroundspace-aroundEqual space around columns
spaceEvenlyspace-evenlyEqual space between and around columns

Examples

Row with Gap and Gutter

<Container>
  <Row gap={16} gutter={8}>
    <Col size={4}>Row 1, Col 1</Col>
    <Col size={4}>Row 1, Col 2</Col>
    <Col size={4}>Row 1, Col 3</Col>
  </Row>
  <Row gap={16} gutter={8}>
    <Col size={6}>Row 2, Col 1</Col>
    <Col size={6}>Row 2, Col 2</Col>
  </Row>
</Container>

Row Override

<Container gap={16}>
  <Row>
    {/* Inherits gap=16 */}
    <Col size={6}>Normal gap</Col>
    <Col size={6}>Normal gap</Col>
  </Row>
  <Row gap={0}>
    {/* Override: no gap */}
    <Col size={6}>No gap</Col>
    <Col size={6}>No gap</Col>
  </Row>
  <Row gap={32}>
    {/* Override: wider gap */}
    <Col size={6}>Wide gap</Col>
    <Col size={6}>Wide gap</Col>
  </Row>
</Container>

Row-Level Sizing

Set a default size for all children:

<Row size={{ xs: 12, md: 4 }}>
  <Col>Each col is 4/12 on md+</Col>
  <Col>Each col is 4/12 on md+</Col>
  <Col>Each col is 4/12 on md+</Col>
</Row>

Standalone Row

Rows can work without a Container:

<Row gap={16} columns={12}>
  <Col size={6}>Left</Col>
  <Col size={6}>Right</Col>
</Row>

On this page