135
berlin amsterdam san francisco stuttgart edenspiekermann_ Niagara! ovvero un manuale pratico per sopravvivere alla cascata Matteo Cavucci CssDay Italia 27 Marzo 2015

NIAGARA! - a practical guide to surviving the css

Embed Size (px)

Citation preview

Page 1: NIAGARA! - a practical guide to surviving the css

berlin amsterdam san francisco stuttgart

edenspiekermann_

Niagara! ovvero un manuale pratico per sopravvivere alla cascata

Matteo Cavucci

CssDay Italia

27 Marzo 2015

Page 2: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Project love curve

2

Page 3: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Project love curve

3

CSS

Page 4: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

I am a

Front-end developer

Page 5: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_ 5

Page 6: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

edenspierkermann_ strategy design communication

Page 7: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Page 8: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Yep, him.

Page 9: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

edenspierkermann_ strategy design communication

Page 10: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Page 11: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

CSS

ME

Page 12: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

12

Page 13: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

12

Page 14: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

⇢ What is the cascade?

12

Page 15: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

⇢ What is the cascade?

⇢ Why is easy to make a mess?

12

Page 16: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

⇢ What is the cascade?

⇢ Why is easy to make a mess?

⇢ How to to survive? With real examples!

12

Page 17: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Table of contents

⇢ What is the cascade?

⇢ Why is easy to make a mess?

⇢ How to to survive?

⇢ How we can get benefits from the cascade? With real examples!

12

Page 18: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

What is the cascade?

Page 19: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“It is an algorithm defining how to combine properties values originating from different sources.”

https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade

Page 20: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Cascading order

User agent

User

Author

15

Page 21: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Cascading order

User agent normal

User agent !important

User normal

Author normal

16

Page 22: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Cascading order

User agent normal

User agent !important

User normal

Author normal

Author !important

User !important

17

Page 23: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Cascading order

1.User agent normal

2.User agent !important

3.User normal

4.Author normal

5.Author !important

6.User !important

18

Page 24: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Cascading order

1.User agent normal

2.User agent !important

3.User normal

4.Author normal

5.Author !important

6.User !important

19

…and specificity!

Page 25: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Specificity order

1.Universal selectors

2.Type selectors

3.Class selectors

4.Attributes selectors

5.Pseudo-classes

6.ID selectors

7.Inline style

20

Page 26: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“Specificity is the means by which a browser decides which property values are the most relevant to an element and gets to be applied.”

https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

Page 27: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to calculate specificity

⇢Add 1 for each element and pseudo-element (for example, :before and :after)

22

Page 28: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to calculate specificity

⇢Add 1 for each element and pseudo-element (for example, :before and :after)

⇢Add 10 for each attribute (for example, [type="text"]), class or pseudo-class (for example, :link or :hover)

23

Page 29: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to calculate specificity

⇢Add 1 for each element and pseudo-element (for example, :before and :after)

⇢Add 10 for each attribute (for example, [type="text"]), class or pseudo-class (for example, :link or :hover)

⇢Add 100 for each ID

24

Page 30: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to calculate specificity

⇢Add 1 for each element and pseudo-element (for example, :before and :after)

⇢Add 10 for each attribute (for example, [type="text"]), class or pseudo-class (for example, :link or :hover)

⇢Add 100 for each ID

⇢Add 1000 for an inline style.

25

Page 31: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Examples!

Page 32: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

p.note

#sidebar p[lang="en"]

27

Page 33: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

p.note 1 element (1) + 1 class (10)

#sidebar p[lang="en"] 1 id (100) + 1 element (1) + 1 attribute (10)

28

Page 34: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

p.note = 11 1 element (1) + 1 class (10)

#sidebar p[lang="en"] = 111 1 id (100) + 1 element (1) + 1 attribute (10)

29

Page 35: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

p.note = 11 1 element (1) + 1 class (10)

#sidebar p[lang="en"] = 111 1 id (100) + 1 element (1) + 1 attribute (10)

30

WIN!

Page 36: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Your turn!

Page 37: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #2

#cssday .intro > h2

.t-cssday .intro__title

32

Page 38: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

#cssday .intro > h2 = 111 1 id (100) + 1 class (10) + 1 element (1)

.t-cssday .intro__title = 20 2 class (10)

33

Page 39: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

#cssday .intro > h2 = 111 1 id (100) + 1 class (10) + 1 element (1)

.t-cssday .intro__title = 20 2 class (10)

34

WIN!

Page 40: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #3

footer nav li:last-child

footer .nav:last-child

35

Page 41: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

footer nav li:last-child = 13 3 element (1) + 1 pseudo-class (10)

footer .nav:last-child = 21 1 element (1) + 1 class (10) + 1 pseudo-class (10)

36

Page 42: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

footer nav li:last-child = 13 3 element (1) + 1 pseudo-class (10)

footer .nav:last-child = 21 1 element (1) + 1 class (10) + 1 pseudo-class (10)

37

WIN!

Page 43: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #4

#cssday input:not([type="submit"])

#cssday .button > a

38

Page 44: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

#cssday input:not([type="submit"]) = 111 1 id (100) + 1 element (1) + 1 pseudo-class (10)

#cssday .button > a = 111 1 id (100) + 1 class (100) + 1 element (1)

39

Page 45: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Example #1

#cssday input:not([type="submit"]) = 111 1 id (100) + 1 element (1) + 1 pseudo-class (10)

#cssday .button > a = 111 1 id (100) + 1 class (100) + 1 element (1)

40

WIN!

Page 46: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Why it’s easy to make a mess?

Page 47: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“the single hardest problem in CSS: getting your rules to match the elements you want, without them accidentally matching the elements you don’t.”

- Philip Walton

Page 48: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

h2 {

border-bottom: 1px solid; font-size: 1.5em; }

43

Page 49: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article"> <h2 class="title">Article Title</h2>

<div class="content"> <p>…</p> </div> </article>

44

Page 50: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article"> <h2 class="title">Article Title</h2>

<div class="content"> <p>…</p> </div> </article>

<!-- The .widget module --> <form class="widget"> <h2 class="title">Widget Title</h2>

<fieldset>…</fieldset> </form>

45

Page 51: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article"> <h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget"> <h2 class="title">Widget Title</h2> <fieldset>…</fieldset> </form>

</div>

</article>

46

Page 52: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

.title {

border-bottom: 1px solid; font-size: 1.5em; }

47

Page 53: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article"> <h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget"> <h2 class="title">Widget Title</h2> <fieldset>…</fieldset> </form>

</div>

</article>

48

Page 54: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article"> <h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget"> <h2 class="title">Widget Title</h2>

<fieldset>…</fieldset> </form>

</div>

49

Page 55: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

.article .title {

border-bottom: 1px solid; font-size: 1.5em; }

.widget .title {

color: gray; text-transform: uppercase; }

50

Page 56: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article">

<h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget"> <h2 class="title">Widget Title</h2> <fieldset>…</fieldset> </form>

</div>

51

Page 57: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article">

<h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget">

<h2 class="title">Widget Title</h2>

<fieldset>…</fieldset> </form>

</div>

52

Page 58: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article">

<h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget">

<h2 class="title">Widget Title</h2>

<fieldset>…</fieldset> </form>

</div>

53

Page 59: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Why it’s easy to make a mess?

<article class="article">

<h2 class="title">Article Title</h2>

<div class="content"> <p>…</p>

<!-- The .widget module --> <form class="widget">

<h2 class="title">Widget Title</h2>

<fieldset>…</fieldset> </form>

</div>

54

Page 60: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Page 61: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Page 62: NIAGARA! - a practical guide to surviving the css

Presentation title here 29.05.2013

Page 63: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“Build systems, not pages.” - Brad Frost

Page 64: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_ 58

Page 65: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_ 58

Page 66: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

⇢ keep stylesheets maintainable

58

Page 67: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

⇢ keep stylesheets maintainable

⇢ keep code transparent, sane, and readable

58

Page 68: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

⇢ keep stylesheets maintainable

⇢ keep code transparent, sane, and readable

⇢ keep stylesheets scalable

58

Page 69: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

How to survive?

Page 70: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Keep CSS specificity low

Page 71: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“Whenever declaring your styles, use the least number of selectors required to style an element.”

- Jonathan Snook

Page 72: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

62

Page 73: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

63

Page 74: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

.css-day h2 { color: tomato; }

64

Page 75: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

.css-day h2 { color: tomato; }

65

Page 76: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

.css-day h2 { color: tomato; }

#css-day { color: tomato; }

66

Page 77: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

.css-day h2 { color: tomato; }

#css-day { color: tomato; }

67

Page 78: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

68

Page 79: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

69

1 single ID

1000 classes!

Page 80: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

70

1 single ID

1000 classes!ID WIN!!!

Page 81: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

71

1 single ID

1000 classes!ID WIN!!!

Page 82: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Keep CSS specificity low

h2.css-day { color: tomato; }

.css-day h2 { color: tomato; }

#css-day { color: tomato; }

.cssday-title { color: tomato; }

72

Page 83: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Use naming conventions

Page 84: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“If I could recommend only one thing out of all this to improve the maintainability and understandability of CSS code, enforcing a naming convention would be it.”

- Ben Frain

Page 85: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“CSS naming conventions is what stands between us and post apocalyptic chaos.”

- Spiros Martzoukos

Page 86: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

<div class="thingy"> <ul class="thingy-bit"> <li class="thingy-bit-item"></li> <li class="thingy-bit-item"></li> </ul> <img class="thingy-wotsit" src="" alt="" /> </div>

76

Page 87: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

.thingy {}

.thingy-bit {}

.thingy-bit-item {}

.thingy-wotsit {}

77

Page 88: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

.thingy {}

.thingy-bit {}

.thingy-bit-item {}

.thingy-wotsit {}

78

Page 89: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

79

Page 90: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

.card {} // block

80

Page 91: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

.card {} // block

.card .title {}

.card .image {}

.card .button {}

81

Page 92: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

.card {} // block

.card .title {}

.card .image {}

.card .button {}

82

Page 93: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

.card {} // block

.card__title {} // element

.card__image {} // element

.card__button {} // element

83

Page 94: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

<article class="card">

<h1 class="card__title">The CSS-day</h1>

<img src="cssdayit.png" alt="The people attending CSS-day IT" class="card__image">

<a class="card__button" href=“/css-day.html“>Read the article</a>

</p> </article>

84

Page 95: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

BEM notation

.card {} // block

.card__title {} // element

.card__image {} // element

.card__button {} // element

.card--featured {} // modifier

85

Page 96: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

<article class=“card card--featured“>

<h1 class="card__title">The CSS-day</h1>

<img src="cssdayit.png" alt="The people attending CSS-day IT" class="card__image">

<a class="card__button" href=“/css-day.html“>Read the article</a>

</p> </article>

86

Page 97: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use naming convention

<article class="news news--awesome">

<h2 class="news__main-title">The CSS-day</h2>

<p class=“news__text”>

<strong class="news__strong">CSS-day</strong> is great! Let's put here some text that <strong class="news__strong">no one</strong> should read, never. Hey, what are you doing, are you <em class="news__emphasis">keep reading?</em>. Stop it, please, and start listen that guy. And forget about <a class="news__link" href="http://whatever.com">your phone</a>.

</p> </article>

87

Page 98: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Use the cascade responsibly

Page 99: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

“While 100% predictable code may never be possible, it’s important to understand the trade-offs you make with the conventions you choose.”

- Philip Walton

Page 100: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

.s-cms-content {

font: 16px/1.5 serif; /* [1] */ h1, h2, h3, h4, h5, h6 { font: bold 100%/1.5 sans-serif; /* [2] */ } a { text-decoration: underline; /* [3] */ } }

90

Page 101: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

<article class="s-cms-content">

<h2>The CSS-day</h2> <p><strong>CSS-day</strong> is great! You, again? As I told you, this is some text that <strong>no one</strong> should read, never. Hey, what are you doing, are you <em>keep reading?</em>. Stop it, please, and start listen this guy. And forget about <a href="http://whatever.com">your phone</a>.</p> </article>

91

Page 102: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

.c-btn {

display: inline-block; padding: 1em; background-color: #333; color: #e4e4e4;

.t-light & {

background-color: #e4e4e4; color: #333; } }

92

Page 103: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

.c-btn {

display: inline-block; padding: 1em; background-color: #333; color: #e4e4e4;

.t-light & {

background-color: #e4e4e4; color: #333; } }

93

Compiled:

.t-light .c-btn {

background-color: #e4e4e4; color: #333; }

Page 104: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

.c-related {

display: table; padding: 1em;

.flexbox & {

display: flex; padding: 0; } }

94

Page 105: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Use the cascade responsibly

.c-related {

display: table; padding: 1em;

.flexbox & {

display: flex; padding: 0; } }

95

Compiled:

.flexbox .c-related {

display: flex; padding: 0; }

Page 106: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Separate container and content

Page 107: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="news-container row">

<article class="news three column">

[...] </article> <article class="news three column">

[...] </article> [...] </section>

97

Page 108: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="news-container row">

<article class="news three column">

[...] </article> <article class="news three column">

[...] </article> [...] </section>

98

Page 109: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="l-latest"> <div class="l-latest__slot"> <article class="c-news">[...]</article> </div> <div class="l-latest__slot"> <article class="c-news">[...]</article> </div> [...] </section>

99

Page 110: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="l-latest">

<div class="l-latest__slot"> <article class="c-news">[...]</article> </div> <div class="l-latest__slot"> <article class="c-news">[...]</article> </div> [...] </section>

100

Page 111: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="l-latest">

<div class="l-latest__slot">

<article class="c-news">[...]</article> </div>

<div class="l-latest__slot">

<article class="c-news">[...]</article> </div>

[...] </section>

101

Page 112: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

<section class="l-latest"> <div class="l-latest__slot"> <article class="c-news">[...]</article>

</div> <div class="l-latest__slot"> <article class="c-news">[...]</article>

</div> [...] </section>

102

Page 113: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

.l-latest {

width: 100%; padding: 0 1rem; } .l-latest__slot {

width: 100%; @media screen and (min-width:60em) { width: 50%; float: left;

103

Page 114: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

Separate container and content

.l-latest {

width: 100%; padding: 0 1rem; } .l-latest__slot {

width: 100%; @media screen and (min-width:60em) { width: 50%; float: left;

104

.c-news {

width: 100%; padding: 1rem; } .c-news__title {

font-size: 1.25rem; @media screen and (min-width:60em) {

font-size: 2rem; }

Page 115: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

keep structure and presentation modular

Page 116: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

keep structure and presentation modular

<section class="fz-s b50 l100 z1 rp">

<article class="d-bk p-md bg-w">

[...] </article> <article class="d-bk p-md bg-w">

[...] </div> [...] </section>

106

Page 117: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

keep structure and presentation modular

// Defines the change of font sizes in different breakpoints. It's used in multiple places, so a mixin seems appropriate.

font-size-responsive() {

font-size: $font-size--base; +mq-min($bp--small) { font-size: $font-size--medium; } +mq-min($bp--medium) { font-size: $font-size--large; } }

107

Page 118: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

headline($level = 1) {

font-family-heavy();

line-height: $line-height--slim;

if ($level == 1) {

font-size: $font-size--xx-large;

line-height: 1.1em;

+mq-min($bp--small) {

font-size: $font-size--xx-large;

}

+mq-min($bp--medium) {

font-size: $font-size--xxx-large;

}

108

keep structure and presentation modular

Page 119: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

if ($level == 2) {

font-size: $font-size--large;

line-height: 1.2em;

+mq-min($bp--small) {

font-size: $font-size--x-large;

line-height: 1.3em;

}

+mq-min($bp--medium) {

font-size: $font-size--xx-large;

line-height: 1.1em;

}

}

109

keep structure and presentation modular

Page 120: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

if ($level == 3) {

font-size: $font-size--medium;

line-height: 1.3em;

+mq-min($bp--small) {

font-size: $font-size--large;

}

+mq-min($bp--medium) {

font-size: $font-size--x-large;

}

}

110

keep structure and presentation modular

Page 121: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

if ($level == 4) {

font-size: $font-size--base;

+mq-min($bp--small) {

font-size: $font-size--medium;

}

+mq-min($bp--medium) {

font-size: $font-size--large;

}

}

111

keep structure and presentation modular

Page 122: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

if ($level > 4) {

font-size: $font-size--small;

+mq-min($bp--small) {

font-size: $font-size--base;

}

+mq-min($bp--medium) {

font-size: $font-size--medium;

}

}

}

112

keep structure and presentation modular

Page 123: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

keep structure and presentation modular

$font-size--xxx-large = 343.75%; //55px

$font-size--xx-large = 300%; //48px

$font-size--xx-large = 225%; //36px

$font-size--x-large = 150%; //24px

$font-size--large = 131.25%; //21px

$font-size--medium = 112.5%; //18px

$font-size--base = 100%; //16px

$font-size--small = 87.7%; //14px

$font-size--micro = 80%; //12.8px

$font-size--nano = 70%; //11.2px

$line-height--base = 1.5;

$line-height--slim = 1.3;

$base-letter-spacing = -0.019em;

$header-letter-spacing = 0.025em;

$font-stack--regular = “CssDayBook“, Arial, "Helvetica Neue", Helvetica, sans-serif;

$font-stack--heavy = “CssDayHeavy", "Arial Black", "Arial Bold", Gadget, sans-serif;

113

Page 124: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

keep structure and presentation modular

// on _c-news.styl

.c-news__title { headline(1);

}

// on _c-card.styl .c-card__title { headline(3);

}

114

Page 125: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Keep in mind

Page 126: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

116

Page 127: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

116

Page 128: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

⇢ Keep CSS specificity Low

116

Page 129: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

⇢ Keep CSS specificity Low

⇢ Use naming convention

116

Page 130: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

⇢ Keep CSS specificity Low

⇢ Use naming convention

⇢ Use the cascade responsibly

116

Page 131: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

⇢ Keep CSS specificity Low

⇢ Use naming convention

⇢ Use the cascade responsibly

⇢ Separate container and content

116

Page 132: NIAGARA! - a practical guide to surviving the css

Niagara! 27.03.2015edenspiekermann_

How to survive:

⇢ Keep CSS specificity Low

⇢ Use naming convention

⇢ Use the cascade responsibly

⇢ Separate container and content

⇢ Keep structure and presentation modular

116

Page 133: NIAGARA! - a practical guide to surviving the css

edenspiekermann_

Page 134: NIAGARA! - a practical guide to surviving the css

berlin amsterdam san francisco stuttgart

edenspiekermann_

Danke.

Matteo Cavucci

[email protected]

www.edenspiekermann.com

Page 135: NIAGARA! - a practical guide to surviving the css

berlin amsterdam san francisco stuttgart

edenspiekermann_

Code examples from:

Inayaili de Leon, Jeremy Keith, Harry Roberts, Philip Walton.

Special thanks to Spiros Martzoukos, Emanuela Damiani.