Layout
CSS utility classes for creating layouts
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.
@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:
.container: Sets a maximum width for the element with a default padding and auto margins..flex: Sets thedisplayproperty of the element toflex..grid: Sets thedisplayproperty of the element togrid.
.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:
To set gaps, use onse of the spacing properties. The default values can be changed using the webcore.config.scss file.
| Class | Default 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 |
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:
| Class | CSS |
|---|---|
.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:
| Class for horizontal alignment | CSS |
|---|---|
.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 alignment | CSS |
|---|---|
.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 |
.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:
| Class | CSS |
|---|---|
.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:
| Class | Layout |
|---|---|
.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:
npx astro add astro-purgecssyarn astro add astro-purgecsspnpm astro add astro-purgecssIf you want to enable the integration manually, follow the steps below:
- Install Dependencies
Install the
astro-purgecssandpurgecsspackages:Terminal window npm install purgecss astro-purgecssTerminal window yarn add purgecss astro-purgecssTerminal window pnpm install purgecss astro-purgecss - Update Configuration
Update your
astro.config.mjsconfiguration file at the root of your project folder with the following lines. Make sure to put thepurgecssintegration as the last element in theintegrationsarray to ensure it works properly.astro.config.mjs import purgecss from 'astro-purgecss'export default {// ...integrations: [purgecss()]}
Request improvement for this page