Top Banner
smacss and bem Design Patterns to Improve your CSS
21

Smacss and bem

Jan 07, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Smacss and bem

smacss and bem

Design Patterns to Improve your CSS

Page 2: Smacss and bem

why modular css?Working on a large project?

A complicated layout?

Working with multiple developers/designers?

Page 3: Smacss and bem

base rules

module styleslayout stylesstate rules

theme rules

Page 4: Smacss and bem

base rules

body, form { margin: 0; padding: 0;}

a { color: #039;}

a:hover { color: #03F; }

Applied to an element using an element selector along with any pseudo-classes.

No class or ID selectors.

Defines default styles for an element

IncludesReset stylesDefault link styles Default font stylesBody backgroundsNever use!important in a

Base style.

Page 5: Smacss and bem

module stylesDiscrete components

Modules can be contained within other modules

They can be easily moved about the layout

● Navigation bar

● Carousel

● Dialog

● Widget

● Article

Page 6: Smacss and bem
Page 7: Smacss and bem
Page 8: Smacss and bem
Page 9: Smacss and bem

layout rules

‘Major’ components of the page

Page 10: Smacss and bem
Page 11: Smacss and bem

state rulesAugments and overrides all other styles

Applied to an element or module

● Active/inactive

● Collapsed/Expanded

● Success/Error

Page 12: Smacss and bem
Page 13: Smacss and bem

B.E.M.

Logical naming structure for your CSS

Page 14: Smacss and bem

what is bem? .block {...}

.block__element {...}

.block__element--modifier{...}Block - Element - Modifier

Page 15: Smacss and bem
Page 16: Smacss and bem

.eventinfo {...}

.eventinfo__title {...}

.eventinfo__image {...}

.eventinfo__date {...}

.eventinfo__detail--location {...}

.eventinfo__detail--time {...}

Page 17: Smacss and bem

.eventinfo {...}

.eventinfo__title {...}

.eventinfo__image {...}

.eventinfo__date {...}

.eventinfo__detail--location {...}

.eventinfo__detail--time {...}

Page 18: Smacss and bem
Page 19: Smacss and bem
Page 20: Smacss and bem
Page 21: Smacss and bem

give bem a try!

It can seem a bit of an ugly duckling at first, but when

used right, it can be incredibly powerful

@thisisjofrank