Skip to content

Instantly share code, notes, and snippets.

@jjcarey
Last active December 6, 2017 22:15
Show Gist options
  • Save jjcarey/6c8f52bdcdc20488fb5b92fde0a50b37 to your computer and use it in GitHub Desktop.
Save jjcarey/6c8f52bdcdc20488fb5b92fde0a50b37 to your computer and use it in GitHub Desktop.
Scalable and Modular Architecture for CSS

Scalable and Modular Architecture for CSS

My Version of the popular CSS architecture.

  • Originally published: June 7, 2015
  • Revised date: April 21, 2016

Summary:

SMACSS, standing for Scalable and Modular Architecture for CSS, is used to structure code for projects large and small. It is a way to examine your design process and as a way to fit those rigid frameworks into a flexible thought process. It is an attempt to document a consistent approach to site development when using CSS. This is a guide to how I deal with the framework.


Base Rules

Base rules (aka Global) is applied to an element using an element selector, a descendent selector, or a child selector, along with any pseudo-classes. It doesn’t include any class or ID selectors. It is defining the default styling for how that element should look in all occurrences on the page.

  • _reset.scss or _normalize.scss CSS Normalize is handled by Foundation
  • _settings.scss Foundation settings file
  • _typography.scss

Helper Rules

Helper rules (aka libraries/ or utils/) folder gathers all Sass tools and helpers used across the project. Sass functions, mixins and placeholders are placed in here. This folder also contains a _variables.scss file which holds all global variables for the project.

  • _variables.scss Theme specific variables handled by Foundation
  • _functions.scss Sass Functions
  • _mixins.scss Sass Mixins
  • _helpers.scss Class & placeholders

Component Rules

Component rules (aka modules/) folder is used for smaller components. It can contain all kinds of specific modules like a slider, a loader, a widget, or anything along those lines. There are usually a lot of files in components/ since your site is should be mostly composed of tiny modules.

  • _buttons.scss
  • _featured-image.scss
  • _dividers.scss
  • _links.scss

Module Rules

Module rules (aka layout/ or partials/) folder is used for larger components. These modules should be a collection of components and layout. Each of them setting some styles for the main sections of the layout (header, footer, and so on).

  • _header.scss
  • _navigation.scss
  • _footer.scss
  • _sidebar.scss

Template Rules

Template rules (aka pages/ or sections/) folder contains page-specific styles. For example, it’s not uncommon to have very specific styles for the home page, so you’d have a _front.scss file in templates/ dealing with this.

  • _front.scss
  • _page-default.scss
  • _page-full-width.scss
  • _page-sidebar-left.scss
  • _single-post.scss

Depending on your deployment process, those files could be called on their own to avoid merging them with the others in the resulting stylesheet. It is really up to you. Where I work, we decided to make them not-partials in order to include them only on pages requiring them. For example, our home page has a very specific layout, compiling to about 200 lines of CSS. To prevent those rules from being loaded on every page, we include this file only on the home page.


This readme file is a compilation of SMACSS Website, SitePoint Article and my collective knowledge.

sass/
|
|– base/
| |– _reset.scss # Reset/normalize
| |– _typography.scss # Typography rules
| ... # Etc…
|
|– components/
| |– _buttons.scss # Buttons
| |– _carousel.scss # Carousel
| |– _cover.scss # Cover
| |– _dropdown.scss # Dropdown
| |– _navigation.scss # Navigation
| ... # Etc…
|
|– helpers/
| |– _variables.scss # Sass Variables
| |– _functions.scss # Sass Functions
| |– _mixins.scss # Sass Mixins
| |– _helpers.scss # Class & placeholders helpers
| ... # Etc…
|
|– modules/
| |– _grid.scss # Grid system
| |– _header.scss # Header
| |– _footer.scss # Footer
| |– _sidebar.scss # Sidebar
| |– _forms.scss # Forms
| ... # Etc…
|
|– templates/
| |– _home.scss # Home specific styles
| |– _contact.scss # Contact specific styles
| ... # Etc…
|
|– themes/
| |– _theme.scss # Default theme
| |– _admin.scss # Admin theme
| ... # Etc…
|
|– vendors/
| |– _foundation.scss # Foundation
| |– _jquery-ui.scss # jQuery UI
| ... # Etc…
|
|
`– main.scss # primary Sass file
`– README.md # explination of structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment