CSS design patterns
These examples are for documenting CSS-specific methodologies / design patterns.
These methodologies include but are not exclusive to the following:
These examples are NOT for documenting CSS frameworks like Bootstrap or Foundation. While you may include examples of how to apply one or more CSS methodology / design pattern with a CSS framework, those examples are to focus on the methodologies / design patterns with that particular framework and on the use of the framework itself.
BEM stands for
Blocks, Elements and Modifiers. It's a methodology initially conceived by Russian tech company Yandex, but which gained quite some traction among American & Western-European web developers as well.
As the same implies, BEM metholology is all about componentization of your HTML and CSS code into three types of components:
Blocks: standalone entities that are meaningful on their own
Elements: Part of blocks that have no standalone meaning and are semantically tied to their blocks.
Modifiers: Flags on a block or element, used to change appearance or behavior
The goal of BEM is to keep optimize the readability, maintainability and flexibility of your CSS code. The way to achieve this, is to apply the following rules.
- Block styles are never dependent on other elements on a page
- Blocks should have a simple, short name and avoid
- When styling elements, use selectors of format
- When styling modifiers, use selectors of format
- Elements or blocks that have modifiers should inherit everything from the block or element it is modifying except the properties the modifier is supposed to modify
If you apply BEM to your form elements, your CSS selectors should look something like this:
The corresponding HTML should look something like this: