0-readme edit
css-classes
edit
How the class names are created and used
CSS classes
A modified BEM style is used fairly consistently for most of the modern code.
General class name patterns
- Standalone component (component not reused)
- Use camelCase:
.StatsRow
- Reusable component
- Use kebob-style with wm- append:
.wm-description-text
- Component's descendants
- Use component style from above, then __kebab-style:
.StatsRow__text-section
.wm-card__text-section
- Modifier that could be used by any descendant element
- Use --kebab-style:
.--cards4
or
.--landscape
- Component state - only used by component
- Use component style from above--kebab-style: this is not currently used anywhere that I can think of.
- Helper and layout classes
- Use alpha-kebab-style
.h-helper-name
(.h-theme-card)
.l-layout-name
(.l-listing)
Important Rules
No more than one selector per css statement
This keeps specificity low and you can easily make changes to your HTML markup without having to refactor a bunch of CSS classes.
✓ Yes: .ComponentName__descendant { ... }
✕ No: .ComponentName .ComponentName__descendant { ... }
Keep BEM one level deep
Using a selector like .block-element1-element2
presumes that element2
will always be a child of element1
in the markup, and you want to avoid that. Just stick to one level of nesting. This:
<div class="blockName">
<div class="blockName__element1">
<div class="blockName__element2"></div>
</div>
</div>
would use the css:
.blockName {
&__element1 {}
&__element2 {}
}
Example of Usage
- Reusable components (
.wm-card
, .wm-description-text
, .wm-statnum
, and all their descendants) control the default look and layout.
- Standalone components have classes that match the reusable components (
.StatsRow__card
, .StatsRow__description-text-title
, etc) so the default classes can be overwritten within each row's css if needed.
- The theme class,
.h-theme-card
, applies a theme to the card (color theme info can found here).
- More information on reusable components can be found here.
<li class="wm-card h-theme-card StatsRow__card">
<!-- visual area with designed text -->
<div class="wm-card__graphic-section StatsRow__graphic-section">
<div class="wm-statnum">
<sup class="wm-statnum--prepend-bottom"></sup>
<sup class="wm-statnum--prepend-top">Top</sup>
<span class="wm-statnum__number">3</span>
</div>
</div>
<!-- text area -->
<div class="wm-card__text-section StatsRow__text-section">
<h4 class="wm-description-text__title StatsRow__description-text-title">
Alt theme</h4>
<div class="wm-description-text__publication StatsRow__description-text-publication">
Barnes & Noble </div>
</div>
</li>