Step-by-step workflow for creating a properly structured BEM SCSS file for a new page or section in this E-learning Rails app. Covers token setup, BEM naming, breakpoints, and integration into the asset pipeline.
Use this skill whenever implementing CSS/SCSS for a new page view, a new landing section, or a significant new UI component that doesn't already have a stylesheet.
Before writing any SCSS, determine:
app/assets/stylesheets/pages/_<page-name>.scss.app/assets/stylesheets/components/_<component-name>.scss.Create the file at the appropriate path. NEVER define local variables or mixins. Instead, import from abstracts/:
// ============================================================
// [PAGE NAME] — Pure SCSS, Strict BEM
// Part of the 7-1 Architectural Pattern
// ============================================================
// ── Shared Tokens (Already available globally via application.scss) ──
// Use variables like $primary, $accent, $bg, $surface, $text-dark, $text-muted
// Use mixins like @include flex-center, @include flex-between, @include line-clamp(2)
// ── Page-Level Styles ─────────────────────────────────────────
.my-page-block {
background: $bg;
@include section-padding;
&__inner {
@include inner-container;
}
}
Define one BEM block per logical UI area. Rules:
.page-name or .component-name (kebab-case).block__element.block--modifierUse mobile-first: styles target 375px base, then add queries:
.my-section {
display: grid;
grid-template-columns: 1fr;
@media (min-width: 768px) {
grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 1440px) {
grid-template-columns: repeat(3, 1fr);
@include inner-container;
}
}
Add the import in the correct layer section:
// 4. Components
@import "components/my-component";
// 5. Pages
@import "pages/my-new-page";
bin/rails server.grep to check).