Use Grid...
- To promote visual consistency from page to page.
- To achieve design flexibility.
- To arrange elements within the Bounded Content.
Don't use Grid...
- Around full width elements (navigation, footer, Promo Bar, Banner).
- Within Carousel (not supported).
- To lay out form fields. Use Form instead.
Structure
SWAN’s Grid organizes content into Rows, each comprising up to 12 Columns, separated by a standard Gutter. The Grid consists of three subcomponents:
GridContainer
: this is the root element of the Grid. All its children should beRow
s.Row
: represents a single row within theGridContainer
. EachRow
should exclusively containColumn
s.Column
: serves as a column within aRow
. It can hold any type of content, including a Nested Grid for more complex layouts.
Grid Container
Divider
Use dividers
to add vertical lines between each Column
.
Tight gutter
Use gutter="tight"
to narrow the gutter between Columns. Only use with Standard Tiles, with skin="product"
.
Row
Overflow
A Row
will display only 12 columns' worth of content per row, but it can contain more than 12. Any extra content will wrap down onto the next line.
Sticky
Use sticky
to make a Column
remain on screen during scrolling, as long as another element in the same row is also visible.
Important: use the sticky
property on both Row
and Column
to achieve this behavior.
Column
Span
In the React API, use span={*}
(0
~12
) to specify how many grid column a Column
spans. In addition, use spanX={*}
to override the column span at a given screen size, where *
is the number of columns.
span
: sets the default size for theColumn
spanXs
: overrides the default size on XS screens (default:12
)spanSm
: overrides the default size on SM screensspanMd
: overrides the default size on MD screensspanLg
: overrides the default size on LG screensspanXl
: overrides the default size on XL screens
In the Vanilla API, use the swan-col-*
(0
~12
) to specify how many grid column a column spans. In addition, use swan-col-X-*
to override the column span at a given screen size, where X
is the screen size and *
is the number of columns.
swan-col-xs-*
: overrides the default size on XS screens (default:12
)swan-col-sm-*
: overrides the default size on SM screensswan-col-lg-*
: overrides the default size on MD screensswan-col-lg-*
: overrides the default size on LG screensswan-col-xl-*
: overrides the default size on XL screens
Use a single Row
to safely contain content exceeding 12 columns. The Row
will display the first 12 columns, then automatically wrap any additional content onto the next line.
Offset
In the React API, use offset={*}
(0
~12
) to create an indentation or widen the gap between grid elements. This property shifts a block to the right by a specified number of column widths. In addition, use offsetX={*}
to create an offset for a certain screen size, where X
is the screen size and *
the number of column offset.
offset
is ignored on XS screens.offsetSm
: creates an offset on SM screens.offsetMd
: creates an offset on MD screens.offsetLg
: creates an offset on LG screens.offsetXl
: creates an offset on XL screens.
In the Vanilla API, use the swan-col-offset-*
(0
~12
) class together with the swan-col-*
class. In addition, use the swan-col-X-offset-*
class to create an offset for a certain screen size, where X
is the screen size and *
the number of column offset.
swan-col-offset
is ignored on XS screens.swan-col-sm-offset-*
: creates an offset on SM screens.swan-col-md-offset-*
: creates an offset on MD screens.swan-col-lg-offset-*
: creates an offset on LG screens.swan-col-xl-offset-*
: creates an offset on XL screens.
Push / Pull
In the React API, use push={*}
(rightward shift) and pull={*}
(leftward shift) to reorder Columns in a Row, to change page layout on different screen sizes. In addition, use pushX={*}
and pullX={*}
to reorder them across different screen sizes, where X
is the screen size and *
the number of column by which the element is pushed or pulled.
push
andpull
are ignored on XS screens.pushSm
andpullSm
: change the column order on SM screens.pushMd
andpullMd:
change the column order on MD screens.pushLg
andpullLg:
change the column order on LG screens.pushXl
andpullXl:
change the column order on XL screens.
In the Vanilla API, use swan-col-push-*
(rightward shift) and swan-col-pull-*
(leftward shift) to reorder Columns in a Row. In addition, use swan-col-X-push-*
and swan-col-X-pull-*
to reorder them across different screen sizes, where X
is the screen size and *
the number of column by which the element is pushed or pulled.
swan-col-push-*
andswan-col-pull-*
is ignored on XS screens.swan-col-sm-push-*
andswan-col-sm-pull-*
: change the column order on SM screens.swan-col-md-push-*
andswan-col-md-pull-*
: change the column order on MD screens.swan-col-lg-push-*
andswan-col-lg-pull-*
: change the column order on LG screens.swan-col-xl-push-*
andswan-col-xl-pull-*
: change the column order on XL screens.
Sticky
Use sticky
to make a Column
remain on screen during scrolling, as long as another element in the same row is also visible. Be aware that enabling stickiness alters the default behavior of the row: it won't vertically stretch all its columns to the same height.
Important: use the sticky
property on both Row
and Column
to achieve this behavior.
In the React API, use unsticky="xs"
on the Column
to override the sticky behavior on Extra-Small screens.
In the Vanilla API, add the class swan-col-unsticky-xs
to the swan-col-*
class to override the sticky behavior on Extra-Small screens.
Flex column
Use flexColumn
to evenly distribute the content of a column vertically in relation to others.
Vertically center content
Use verticallyCenterContent
to vertically center the content within one column relative to the others.
Floating Container
Use floatingContainer
on a child Column
with a specified span
value, to create a container that sits at the top left of the parent Column
. It allows the parent's content to flow and wrap around it.
In the Vanilla API, use the semantically accurate aside
tag instead of a div
when the content in the floating container (i.e. supporting image, quote) is secondary to the main content.
Use floatingContainerAlignment="right
" in addition to floatingContainer
to align it to the right.
Accessibility
Grid as List
In the React API, use as="ul"
on the GridContainer
and as="li"
on the Row
s when the grid contents are semantically part of a list.
In the Vanilla API, use ul
tag with class="swan-grid-container"
and li
tag with class="swan-row"
instead of div
tags.