Slide 1

Slide 1 text

CSS the right way?

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Michael Lancaster @weblancaster @weblancaster Front End Developer

Slide 4

Slide 4 text

What do you think when you hear the word catastrophe?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Code that does not have.. Scalability is a catastrophe Modularity Performance Maintainability Reusability Understanding Flexibility Predictability Consistency

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

CSS bad practices

Slide 12

Slide 12 text

#header { width: 960px; } #aside { width: 260px; float: left; } #content { width: 680px; float: right; } #content #article { width: 100%; padding: 20px; } #content #article #title { font-size: 12px; } #footer{ width: 960px; } Specificity Dude! You are doing it wrong.

Slide 13

Slide 13 text

div#header { width: 960px; } ul#aside { width: 260px; float: left; } ul#aside li.items p.title { text-align: center; font-size: 12px; } div#content div h4 span { font-size: 16px; } Over-qualify Dude! You are doing it wrong.

Slide 14

Slide 14 text

#search .box .lbl .input-txt { width: 250px; } #content div h4 span a { font-size: 16px; } Long-descendants (nesting) Dude! You are doing it wrong.

Slide 15

Slide 15 text

“Don’t style websites. Build Web Applications”

Slide 16

Slide 16 text

The good practices Free tips!

Slide 17

Slide 17 text

• Use classes they are your best friends • Avoid ID’s • Avoid Tag-qualification • Avoid long-descendants (nesting) • Use CSS pre-processors (applying the tips above) • Find patterns on the design and build style guide documentation • Performance matters • Browsers “match” CSS from right to left • Use name convention. CamelCase, camelBack, snake_case. Whatever

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Bonus

Slide 20

Slide 20 text

Three main CSS Methodologies

Slide 21

Slide 21 text

SMACSS BEM OOCSS

Slide 22

Slide 22 text

SMACSS (Scalable and Modular Architecture for CSS) • Base • Layout • Module • State • Theme

Slide 23

Slide 23 text

Base

Slide 24

Slide 24 text

body { font-size: 62.5%; background: #fff; color: #000; } a { color: #ababab; } a:hover { color: #3a3a3a; } h1, h2, h3 { text-transform: uppercase; }

Slide 25

Slide 25 text

Layout

Slide 26

Slide 26 text

#header, #container, #footer { width: 960px; margin: 0 auto; } #sidebar { width: 300px; float: left; } #content { width: 600px; float: right; }

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Module

Slide 30

Slide 30 text

.module > h2 { font-size: 22px; color: #ccc; } .module > p { font-size: 12px; color: #333; } .module > strong { text-transform: uppercase; }

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

States

Slide 33

Slide 33 text

.is-hidden { display: none; } .tab { background: #555; color: #fff; } /* overwrite default styling */ .is-tab-active { background: #fff; color: #555; }

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Themes

Slide 37

Slide 37 text

/* module.css */ .module { background: #333; } .module > p { color: #fff; } /* theme-clean.css */ .module { background: #fff; } .module > p { color: #333; }

Slide 38

Slide 38 text

BEM (Block Element Modifier) • Block • Element • Modifier

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Block

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Element

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

/* code example */

Logo

Slide 47

Slide 47 text

Modifier

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

/* code example modifier */

Logo

Slide 51

Slide 51 text

OOCSS (Object Oriented CSS) • Separate structure and skin • Separate Content and Container

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Objective • Flexibility • Create a component library • Minimize Selectors • Extend objects applying classes • Use consistent styles • Build HTML and style from the component library

Slide 54

Slide 54 text

.header { background: #fbfbfb; width: 960px; box-shadow: 0px 2px 2px #AAA; border: 1px solid #AAA; margin: 10px; } .content { background: #fbfbfb; width: 960px; box-shadow: 0px 2px 2px #AAA; border: 1px solid #AAA; margin: 10px; } .footer { background: #fbfbfb; width: 960px; box-shadow: 0px 2px 2px #AAA; border: 1px solid #AAA; margin: 10px; } not OOCSS

Slide 55

Slide 55 text

.main-theme { background: #fbfbfb; box-shadow: 0px 2px 2px #AAA; border: 1px solid #AAA; } .main-template { width: 960px; margin: 10px; } OOCSS!

Slide 56

Slide 56 text

.bt { border: 1px solid rgba(0, 0, 0, 0.25); color: #444; margin: 0px 5px; height: 29px; width: 65px; padding: 8px 13px; background-image: -webkit-linear-gradient(#ededed, #ededed 38%, #dedede); text-shadow: 0 1px 0 rgb(240, 240, 240); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08), inset 0 1px 2px rgba(255, 255, 255, 0.75); font-size: 12px; } .bt.bt-dark { -webkit-linear-gradient(#693B3B, #B8B2B2 38%, #dedede); } .bt.bt-big { height: 45px; width: 100px; font-size: 16px; }

Slide 57

Slide 57 text

And what’s the best Methodology? SMACSS? BEM? OOCSS?

Slide 58

Slide 58 text

The one that apply.. Scalability Modularity Performance Maintainability Reusability Understanding Flexibility Predictability Consistency to your team

Slide 59

Slide 59 text

There’s no such thing as “the god master way”. But there’s definitely great practices.

Slide 60

Slide 60 text

Thanks @weblancaster @weblancaster