Columns ​

The columns layout provides a set of classes to arrange content in a responsive CSS grid.

Columns use CSS Grid to size columns automatically and keep them aligned across rows. If you need more control over the width of each item, use Flex columns.

Base class ​

The .columns class puts a container's direct children in a grid with three columns by default. The grid will responsively use fewer columns if there isn't enough room.

Note

Column widths are based on --graupl-content-max-width by default. These examples set --graupl-columns-content-max-width to 100% so the column widths adjust to the space available in the preview.

Column count and width ​

Use .count-1 through .count-12 on the container to set how many columns the grid should fit when there's enough room.

When there are fewer items than columns, the occupied columns stretch to fill the unused space. Add .fixed to keep them at their calculated width.

Column spans ​

Use .span-1 through .span-12 on a direct child to set how many columns it spans.

Responsive variants ​

A screen-size prefix applies a class at that breakpoint and above. Use prefixed count and fixed classes on the container, such as md:count-2 or md:fixed, and prefixed span classes on the grid item, such as md:span-2.

Use count-2 lg:count-3 to set two columns by default and three from the large screen breakpoint. A grid can still stack on a wide screen because Graupl applies a single-column fallback inside query containers up to 575px wide. A responsive span such as md:span-2 can override the fallback for that item.

See responsive utility classes for the available prefixes.

Variants ​

By default, no theme variants are generated.

If you are compiling your own version of Graupl, you can set the columns module’s $themeable variable to true to generate the .primary, .secondary, and .tertiary variants.

Custom Properties ​

The following custom properties can be used to customize the columns layout:

PropertyDescriptionDefault Value
--graupl-columns-row-gapThe gap between the rows of the columns.var(--graupl-spacer-5)
--graupl-columns-column-gapThe gap between the columns of the columns.var(--graupl-spacer-5)
--graupl-columns-countThe target column count used to calculate the minimum column width.3
--graupl-columns-content-max-widthThe reference width used to calculate the minimum column width.var(--graupl-content-max-width)
--graupl-columns-min-widthThe minimum width of each column.calc((var(--graupl-columns-content-max-width) - var(--graupl-columns-column-gap) * (var(--graupl-columns-count) - 1)) / var(--graupl-columns-count))
--graupl-columns-max-widthThe maximum width of each column.1fr
--graupl-columns-grid-template-columnsThe grid template columns for the columns.repeat(auto-fit, minmax(var(--graupl-columns-min-width), var(--graupl-columns-max-width)))
--graupl-columns-spanThe number of columns a grid item spans.1
--graupl-columns-backgroundThe background of the columns component.No default
--graupl-columns-colorThe text color of the columns component.No default

Sass variables ​

The following Sass variables can be used to customize the generation of the columns layout:

VariableDescriptionDefault Value
$selector-baseThe base selector for the component."."
$modifier-selector-baseThe base selector for component modifiers."."
$generate-base-theme-mapFlag to generate the base theme map.true
$themeableFlag to generate theme modifiers.false
$screen-awareEnables screen-aware column variants.true
$theme-awareEnables theme-aware column variants.false
$scheme-awareEnables scheme-aware column variants.false
$state-awareEnables state-aware column variants.false
$container-awareAllows container-aware variants when enabled globally.true
$force-single-columnsEnables a single column in narrow query containers.true
$columns-selector-baseThe base selector for the columns component."."
$columns-selectorThe selector for the columns component."columns"
$columns-theme-selector-baseThe selector base for columns theme modifiers."."
$columns-theme-selector-prefixThe columns theme modifier selector prefix.""
$columns-count-selector-baseThe base selector for the count class."."
$columns-count-selector-prefixThe prefix for the count class."count-"
$columns-span-selector-baseThe base selector for the span class."."
$columns-span-selector-prefixThe prefix for the span class."span-"
$columns-fixed-selector-baseThe base selector for the fixed class."."
$columns-fixed-selectorThe selector for the fixed class."fixed"
$columns-screen-aware-selector-prefixPrefix to the screen-aware portion of column selectors.""
$columns-screen-aware-selector-suffixSuffix to the screen-aware portion of column selectors.""
$columns-screen-aware-selector-separatorSeparator inserted for screen-aware column selectors."\\:"
$columns-theme-aware-selector-prefixPrefix to the theme-aware portion of column selectors.""
$columns-theme-aware-selector-suffixSuffix to the theme-aware portion of column selectors."-theme"
$columns-theme-aware-selector-separatorSeparator inserted for theme-aware column selectors."\\:"
$columns-scheme-aware-selector-prefixPrefix to the scheme-aware portion of column selectors.""
$columns-scheme-aware-selector-suffixSuffix to the scheme-aware portion of column selectors."-mode"
$columns-scheme-aware-selector-separatorSeparator inserted for scheme-aware column selectors."\\:"
$columns-state-aware-selector-prefixPrefix to the state-aware portion of column selectors.""
$columns-state-aware-selector-suffixSuffix to the state-aware portion of column selectors.""
$columns-state-aware-selector-separatorSeparator inserted for state-aware column selectors."\\:"
$columns-container-aware-selector-prefixPrefix to the container-aware portion of column selectors."cq\\:"
$columns-container-aware-selector-suffixSuffix to the container-aware portion of column selectors.""
$columns-container-aware-selector-separatorSeparator inserted for container-aware column selectors."\\:"
$columns-max-widthThe maximum width of each column.1fr
$columns-countThe default number of columns.3
$columns-min-countThe minimum number of columns used to generate .count-# classes.1
$columns-max-countThe maximum number of columns used to generate .count-# classes.12
$columns-spanThe default span of each column.1
$columns-theme-mappingsMap of properties/shades for columns themes.()
$columns-theme-mapExpanded map of properties/colors/shades.()