SMACSS
SMACSS
What is SMACSS?
Scalable and Modular Architecture for CSS. “A flexible guide for developing sites small and large”.
SMACSS (pronounced “smacks”) is more of a style guide than a rigid framework. There is no library for us to download or install. There is no git repository for us to clone.This way of approaching was developed and made as a book by the author Jonathan Snook.This way of structuring our CSS allows for flexibility and maintainability as our project and our team grows.
SMACSS is a bit different from CSS frameworks like bootstrap, materialize css, foundation etc., Instead, SMACSS is more like a template or frame. The ultimate aim of SMACSS is dividing all the styles files or folders into 5 different categories. This approach in our project must contain the following folders.
Base
Layout
Modules
States
Themes
Base:
Base rules usually define what an element should like in all occurrences on the page. It is simply said as default styling of an element. In this we should not include any class or ID selector. It must contain only the selector, descendant selector or a child selector.
Eg: Base folder must contain files like these
_reset or _normalize
_base
Layout:
Layout is dividing the page into major and minor components. The major components are top level components like header, footer, article. These are usually styled using the ID selectors.
In this we should prefix the styles with letter “l” to distinguish it from the modules.
Eg: Layout folder must contain files like these
_container
_grid
_responsive
Modules:
Modules are discrete components on the page that are reusable and part of a single layout. So these modules should be styled as a standalone component. Here we should avoid using the IDs and element selectors. These classes may be prefixed with the letter ‘m’.
Eg: Module folder must contain files like these
_comments
_buttons
_forms
State:
States are just augments and overrides of the styles. For example, the accordion section may be in the state of expand or collapse. Similarly, A message may be in the state of success or error.
There is plenty of similarity between a sub-module style and a state style. They both modify the existing look of an element. These classes may be prefixed with the letter ‘is’.However, they differ in two key ways:
State styles can apply to layout and/or module styles; and
State styles indicate a JavaScript dependency
Eg: States folder must contain files like these
1. _hidden
2. _active
3. _collapsed
Theme:
It is used to contain the rules of the primary colors, shapes, borders, shadows, and such.This folder can be simply defined as a utility folder. Mostly these are elements which repeat across a whole website. We don’t want to redefine them each time ,instead we can define a unique class which we only add on later to a default element.We must not get confused with base rules. These rules are completely different. Moreover, we are restyling the elements in the BASE folder.
Overall SMACSS is just a CSS architecture and it does what it says on the tin—nothing more and nothing less.
Eg: Theme
_variables,
_mixins
Thanks for reading. To boost your computer science knowledge, I firmly recommend you to get along with our posts.
Comments
Post a Comment