Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

37
1 / CSS Coding Conventions CSS Naming Conventions Improve your code with OOCSS, SMACSS, DRY and BEM Rodrigo Castilho aka RODCAST Senior Front End Engineer @rodcast 07/10/2014

description

In this presentation you will see why the conventions (OOCSS, SMACSS, DRY and BEM) are important for your business, how you can to improve the performance, maintainability and solving problems/issues quickly for produce better web sites. CSS are changing over time and today with several devices and responsive web design you need to have in your mind the best practices for create your CSS. Obviously that we need to use a preprocessor (LESS, SASS, Stylus) because with the preprocessor you can to use variables, mixins, nested rules, inheritance, operations, extended and much more that will ease your life. Naming Convention is very important in any language because clarifies intent.

Transcript of Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

Page 1: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

1 /

CSS Coding Conventions CSS Naming Conventions Improve your code with OOCSS, SMACSS, DRY and BEM Rodrigo Castilho aka RODCAST Senior Front End Engineer @rodcast 07/10/2014

Page 2: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 2

CSS is a Mess CSS is easy? CSS is messy!

Page 3: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 3

Make a CSS better Make it simple, short and above all describe what you are seeing.

Page 4: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

4 /

HOW TO: Clean and Organize your CSS!

•  Use a name that describes what you are styling

•  Indents and Space (all lowercase)

•  Avoid IDs selectors in CSS

•  Minimize the depth of CSS selectors

•  Use classes to define visual presentation patterns

Page 5: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

5 /

HOW TO: Clean and Organize your CSS!

•  Use a name that describes what you are styling

•  Indents and Space (all lowercase)

•  Avoid IDs selectors in CSS

•  Minimize the depth of CSS selectors

•  Use classes to define visual presentation patterns

Page 6: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

6 /

HOW TO: Clean and Organize your CSS!

•  Use a name that describes what you are styling

•  Indents and Space (all lowercase)

•  Avoid IDs selectors in CSS

•  Minimize the depth of CSS selectors

•  Use classes to define visual presentation patterns

Page 7: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

7 /

HOW TO: Clean and Organize your CSS!

•  Use a name that describes what you are styling

•  Indents and Space (all lowercase)

•  Avoid IDs selectors in CSS

•  Minimize the depth of CSS selectors

•  Use classes to define visual presentation patterns

Page 8: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

8 /

HOW TO: Clean and Organize your CSS!

•  Use a name that describes what you are styling

•  Indents and Space (all lowercase)

•  Avoid IDs selectors in CSS

•  Minimize the depth of CSS selectors

•  Use classes to define visual presentation patterns

Page 9: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 9

OOCSS Object Oriented CSS by Nicole Sullivan

Page 10: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

10 /

Why I should use OOCSS? OOCSS force you to think the website as a whole…

Page 11: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

11 /

Two main principles of OOCSS

•  Separate Structure and Skin

•  Separate Container and Content

Page 12: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

12 /

Two main principles of OOCSS

•  Separate Structure and Skin

•  Separate Container and Content

Page 13: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 13

SMACSS (pronounced “smacks”) Scalable and Modular Architecture for CSS by Jonathan Snook

Page 14: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

14 /

Are divided in categories

•  Base

•  Layout

•  Module

•  State

•  Theme

Page 15: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

15 /

Are divided in categories

•  Base

•  Layout

•  Module

•  State

•  Theme

Page 16: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

16 /

Are divided in categories

•  Base

•  Layout

•  Module

•  State

•  Theme

Page 17: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

17 /

Are divided in categories

•  Base

•  Layout

•  Module

•  State

•  Theme

Page 18: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

18 /

Are divided in categories

•  Base

•  Layout

•  Module

•  State

•  Theme

Page 19: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

19 /

Naming Convention

module-submodule--modifier

module--modifier

module-submodule

module-submodule--modifier

Page 20: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 20

DRY CSS Don't Repeat Yourself by Jeremy Clarke

Page 21: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

21 /

Two important things

•  Less Code

•  Decouple your CSS

Page 22: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

22 /

Two important things

•  Less Code

•  Decouple your CSS

Page 23: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 23

BEM Block, Element, Modifier by guys Yandex

Page 24: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

24 /

Are divided in categories

•  Block

•  Element

•  Modifier

Page 25: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

25 /

Are divided in categories

•  Block

•  Element

•  Modifier

Page 26: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

26 /

Are divided in categories

•  Block

•  Element

•  Modifier

Page 27: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

27 /

Naming Convention

block__element--modifier

block--modifier

block__element

block__element--modifier

Page 28: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 28

Organize CSS properties

Page 29: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

29 /

Declaration order

•  by Alphabetical

•  by Group

Page 30: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

30 /

Declaration order

•  by Alphabetical

•  by Group

Page 31: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

/ 31

Summary

Page 32: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

32 /

The goals

Predictable, Reusable, Maintainable and Scalable.

Use best practices, make a simple and logic CSS with all experience and continue learning and when possible refactor your code.

The more you learn the better you are, but there is always more learning to be done and have in your mind, you can to change every time with maintenance. In other scenario, have a standard independent of your choice.

The less time you spend with your CSS, more time you have to improve your knowledge and your code.

Page 33: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

33 /

Don’t forget

Never stop refactoring your code,

otherwise you'll have to fix a lot of broken

windows sooner than you think.

Page 34: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

34 /

Reference list: Books

Scalable and Modular Architecture for CSS By Jonathan Snook

It’s available on: http://shop.smacss.com/

Page 35: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

35 /

Reference list: Links

http://oocss.org/

http://stubbornella.org/

http://smacss.com/

http://snook.ca/

http://bem.info/

http://csslint.net/

http://suitcss.github.io/

https://github.com/styleguide/css

https://github.com/csswizardry/CSS-Guidelines

https://github.com/work-club/CSS-Coding-Standards

http://www.vanseodesign.com/css/dry-principles/

Page 36: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

36 /

Homer Simpson WOOHOO!!! I hope I haven't forgotten anything.

Page 37: Tech Headline - CSS Naming Conventions: Improve your code with OOCSS, SMACSS, DRY and BEM

Thank You.