Search documentation v0.9.0

Layout

CSS utility classes for creating layouts

Source ↗️ Report Issue ↗️

Webcore comes with a handful of CSS utility classes to help you build layouts faster. To use utility classes, you must have the includeUtilities rule set to true in your setup mixin. This is enabled by default. If you’d like to exclude utility classes from your CSS bundle, make sure to set this rule to false.

Utilities must not be disabled in your setup to use them
@use 'webcoreui/styles' as *;
@include setup((
...,
includeUtilities: false // Remove this option if you want to use utility classes
));

Utilities comes with the following three base classes:

You can also use the Flex and Grid components to build responsive layouts.
.container with a max-width, padding, and auto margins

Flex

When setting the .flex class on an element, you’ll be able to use the following utility classes to change its appearance:

Gaps
.flex.xxs
.flex.xs
.flex.sm

To set gaps, use onse of the spacing properties. The default values can be changed using the webcore.config.scss file.

ClassDefault value
.none 0
.xxs 2px
.xs 5px
.sm 10px
.md 15px
.default 20px
.lg 25px
.xl 30px
.xl2 35px
.xl3 40px
.xl4 45px
.xl5 50px
Note
Due to class naming requirements, 2xl, 3xl, 4xl, and 5xl spacing values can be used with the .xl2, .xl3, .xl4, and .xl5 classes.

Direction

To change the direction of your flex items, you can use the .row, .column, .row-reverse, and .column-reverse classes:

.row
1
2
3
4
.column
1
2
3
4
.row-reverse
1
2
3
4
.column-reverse
1
2
3
4
ClassCSS
.row flex-direction: row
.column flex-direction: column
.row-reverse flex-direction: row-reverse
.column-reverse flex-direction: column-reverse

Alignment

To change the vertical and horizontal alignments of flex items, you can use the following CSS classes:

.justify-start
1
2
3
.justify-end
1
2
3
.justify-center
1
2
3
.justify-between
1
2
3
.justify-around
1
2
3
.justify-evenly
1
2
3
Class for horizontal alignmentCSS
.justify-start justify-content: flex-start
.justify-center justify-content: center
.justify-end justify-content: flex-end
.justify-between justify-content: space-between
.justify-around justify-content: space-around
.justify-evenly justify-content: space-evenly
.justify-stretch justify-content: stretch
Class for vertical alignmentCSS
.items-start align-items: flex-start
.items-center align-items: center
.items-end align-items: flex-end
.items-baseline align-items: baseline
.items-stretch align-items: stretch
Use the .center class to set both justify-content and align-items to center.

Wrap

To change the way flex items wrap, use the .wrap, .nowrap, or .wrap-reverse classes:

.wrap
1
2
3
4
5
.nowrap
1
2
3
4
5
.wrap-reverse
1
2
3
4
5
ClassCSS
.wrap flex-wrap: wrap
.nowrap flex-wrap: nowrap
.wrap-reverse flex-wrap: wrap-reverse

Responsive classes

The above classes can be used responsively by prefixing them with a specific breakpoint (xs, sm, md, lg):

<!-- Flex gap, alignment, direction, and wrap for xs -->
<div class="xs-md" />
<div class="xs-justify-center" />
<div class="xs-column" />
<div class="xs-wrap" />
<!-- sm -->
<div class="sm-md" />
<div class="sm-justify-center" />
<div class="sm-column" />
<div class="sm-wrap" />
<!-- md -->
<div class="md-md" />
<div class="md-justify-center" />
<div class="md-column" />
<div class="md-wrap" />
<!-- lg -->
<div class="lg-md" />
<div class="lg-justify-center" />
<div class="lg-column" />
<div class="lg-wrap" />

To configure your breakpoints, please see our CSS configuration guide.

Grid

Setting gaps and alignments for grids can be done using the same classes as shown above for .flex elements. To change the number of grid columns on your page, you can use the following CSS classes:

col-2
col-2
sm-3
sm-3
sm-3
sm-4
sm-4
sm-4
sm-4
ClassLayout
.col-2 Two-column layout
.col-3 Three-column layout
min-width: 600px: -
.xs-2 Two-column layout
.xs-3 Three-column layout
.xs-4 Four-column layout
min-width: 800px: -
.sm-2 Two-columns
.sm-3 Three-columns
.sm-4 Four-columns
min-width: 1024px: -
.md-2 Two-columns
.md-3 Three-columns
.md-4 Four-columns
.md-5 Five-columns
.md-6 Six-columns
min-width: 1200px: -
.lg-2 Two-columns
.lg-3 Three-columns
.lg-4 Four-columns
.lg-5 Five-columns
.lg-6 Six-columns
.lg-7 Seven-columns
.lg-8 Eight-columns

Optimization

Enabling layout-specific classes in your project can negatively affect your CSS bundle size if you don’t utilize all available classes. In order to get rid of unused CSS classes, add the astro-purgecss package to your project using one of the following commands:

Terminal window
npx astro add astro-purgecss
Terminal window
yarn astro add astro-purgecss
Terminal window
pnpm astro add astro-purgecss

If you want to enable the integration manually, follow the steps below:


Request improvement for this page