-
Notifications
You must be signed in to change notification settings - Fork 0
CSS Guide
Overall you'll most likely be writing far fewer lines of CSS thanks to the Tailwind tooling of the theme. However, CSS files are here to act as a supplement to Tailwind styles in places like typography classes, component specific tweaks, button styles, etc. See below for the b-b-b-breakdown.
The sass folder is initially structured into 4 directories:
Each directory houses CSS files that have access to token definitions, tailwind utilities, and variable definitions.
This directory contains resets, tailwind imports, and utility classes. As well, this directory is the landing zone for generated variable definition files. The _generated-variables.css
file here will provide CSS variables for each token. Changes to this file will be overwritten but the npm run format.tokens
command.
This directory contains theme primitives such as buttons and typography.
This directory is similar to the Pages directory in that it's meant for edge case overrides, fine grain tweaks, or tailwind definition grouping for individual components. Adding a file with the component-name and using bem syntax you can include those rules.
This directory contains page level styles that aren't handled for by component tailwind classes. If you need to override a given page hero or another page section, add a file with the corresponding page-title to this directory and include those rules.
All files in this directory have access to Tailwind's tooling and definitions via the @apply
syntax. As well you can include token definitions via the generated variables in the Global directory. Some theme level definitions will be required as the project is getting setup.
In the css/common/typography.css
file you can define classes for each type of html template tag. Some basic definitions have been provided mostly via @apply
ing generated tailwind rules i.e.
body {
@apply font-sans;
}
.h1,
.h2 {
@apply font-serif;
}
These definitions will want to get enhanced and built out according to the project but will jump start the work.
Similar to typography in the css/common/buttons.css
file you can define global styles for buttons on the site. Again, some basic definitions have been provided mostly via @apply
ing generated tailwind rules. However, buttons in particular will need to be built out according to the project designs.
We're using the PostCSS engine to power up basic CSS. The syntax is slightly different from SCSS to CSS.
SCSS:
$blue: #0000FF;
CSS:
:root {
--blue: #0000FF;
}
SCSS:
color: $blue;
CSS:
color: var(--blue);
SCSS: defined and applied with a mixin
@mixin mq($screen) {
@if ($screen == "md") {
@media (min-width: 769px) {
@content;
}
}
}
...
@include mq(md) {
color: $blue;
}
CSS: defined and applied with custom css media queries
@custom-media --bp-md (min-width: 769px);
@media (--bp-md) {
color: var(--blue);
}
SCSS:
.field-name {
.field-child {
color: $magenta;
}
&.field-modifier {
color: $blue;
}
}
CSS:
.field-name {
.field-child {
color: var(--magenta);
}
&.field-modifier {
color: var(--blue);
}
}
For more detail on nesting in particular see the postcss-nested plugin docs.
Use a class instead. If styles need to be repeated, try adding a new utility, or using a reusable twig template.
There are no extends. However, @apply
is here in a pinch.