Slide 1

Slide 1 text

https://www.flickr.com/photos/h-k-d/5093579727/ Futureproof styling 
 (in Drupal 8) by Tamás Hajas

Slide 2

Slide 2 text

Tamás Hajas Drupal / Web Project Manager & Front-end Developer Integral Vision Ltd https://thamas.github.io

Slide 3

Slide 3 text

CSS is easy

Slide 4

Slide 4 text

more than 
 300
 .css files in Drupal 8.0.0 325

Slide 5

Slide 5 text

almost 
 116 000
 characters in CSS loaded by Drupal 8.0.0 115 894

Slide 6

Slide 6 text

CSS is easy to do wrong!

Slide 7

Slide 7 text

body.node-19 #sidebar-first div.block .title a { color: red !important; }

Slide 8

Slide 8 text

Ask yourself!

Slide 9

Slide 9 text

body.node-19 #sidebar-first div.block .title a { color: red !important; }

Slide 10

Slide 10 text

@if body { @if .node-19 { @if #sidebar-first { @if div { @if .block { @if .title { @if a { color: red !important; } } } } } } } Cyclomatic Complexity

Slide 11

Slide 11 text

KISS http://chamaeleontour.com/2014/02/25/kiss-forever-band-hungary-in-melle/

Slide 12

Slide 12 text

Keep It Simple, Stupid http://chamaeleontour.com/2014/02/25/kiss-forever-band-hungary-in-melle/

Slide 13

Slide 13 text

body.node-19 #sidebar-first div.block .title a { color: red !important; } Are you sure, it is red, because it is in… … .title? … .block? … #sidebar-first? … body? Context?

Slide 14

Slide 14 text

body.node-19 #sidebar-first div.block .title a { color: red !important; } Are you sure, it is red, because it is in… … .title? … .block? … #sidebar-first? … body?! Context? Seriously?!

Slide 15

Slide 15 text

“Basically, cosmetics should not change depending on the location of the component.” –Harry Roberts

Slide 16

Slide 16 text

#sidebar-first div.block .title a { color: #fff; } Undoing things :( body.node-19 #sidebar-first div.block .title a { color: red !important; } div.block .title a { color: #333; }

Slide 17

Slide 17 text

Specificity :( body.node-19 #sidebar-first div.block .title a { color: red !important; } 0001 0001 0001 0010 0010 0010 0100 0,1,3,3

Slide 18

Slide 18 text

Specificity :( 1,2,12,15

Slide 19

Slide 19 text

Keep specificity low! https://www.flickr.com/photos/freetheimage/14741164059

Slide 20

Slide 20 text

KISS Context? Specificity OK, but… How?!

Slide 21

Slide 21 text

Flat selectors

Slide 22

Slide 22 text

body.node-19 #sidebar-first div.block .title a { color: red !important; } .promo-title { color: $color-brand; } Flat selectors

Slide 23

Slide 23 text

Object vs. Component Concrete Abstract

Slide 24

Slide 24 text

…

Slide 25

Slide 25 text

…

Object

Slide 26

Slide 26 text

…

Component

Slide 27

Slide 27 text

.o-media { display: table; width: 100%; } .c-testimonial { padding: $base-spacing-unit; border-radius: $base-radius; background-color: $color-shadow; color: $color-text; } Object vs. Component

Slide 28

Slide 28 text

…

“Namespaces”

Slide 29

Slide 29 text

Single responsibility principle .button-login { display: inline-block; padding: 2em; background-color: $color-brand-sec; color: $color-text--inverse; } Mixing responsibilities Base Structural Cosmetic

Slide 30

Slide 30 text

Single responsibility principle .button { display: inline-block; } .button--large { padding: 2em; } .button--positive { background-color: $color-brand-sec; color: $color-text--inverse; }

Slide 31

Slide 31 text

.o-media { display: table; width: 100%; } .c-testimonial { padding: $base-spacing-unit; border-radius: $base-radius; background-color: $color-shadow; color: $color-text; } Object vs. Component

Slide 32

Slide 32 text

DRY http://vicvapor.com/cracked-desert-background

Slide 33

Slide 33 text

Don’t Repeat Yourself! $spacing-unit: 20px; .u-margin-top { margin-top: $spacing-unit * 1.5; } .u-margin-right { margin-right: $spacing-unit ; } .u-margin-bottom { margin-bottom: $spacing-unit / 2; } .u-margin-left { margin-left: $spacing-unit; }

Slide 34

Slide 34 text

Open / Closed principle for extension for modification .button { … padding: 1em 2em; } #sidebar .button { padding: 1.5em 2.5em; } It is modified 
 by “context”

Slide 35

Slide 35 text

Open / Closed principle for extension for modification .button { … padding: 1em 2em; } .button--large { padding: 1.5em 2.5em; }

Slide 36

Slide 36 text

Classicists?!

Slide 37

Slide 37 text

body.node-19 #sidebar-first div.block .title a { color: red !important; } Is this better?

Slide 38

Slide 38 text

Wait! It’s Drupal!

Slide 39

Slide 39 text

No! It’s Drupal 8!

Slide 40

Slide 40 text

• Forgot Classy! Use Stable! • Forgot about Drupal! • Use a Styleguide! Think!

Slide 41

Slide 41 text

Templates

Slide 42

Slide 42 text

You can use Sass 
 mixins and extends* * if it is needed

Slide 43

Slide 43 text

CSS Structure

Slide 44

Slide 44 text

by Harry Roberts Invented Triangle CSS

Slide 45

Slide 45 text

Settings Tools Generic Base Objects Components Utils generic explicit far-reaching localized

Slide 46

Slide 46 text

There is NO One Right Way!

Slide 47

Slide 47 text

There is NO One Right Way!

Slide 48

Slide 48 text

1. Think & Decide 2. Communicate 3. Use strict

Slide 49

Slide 49 text

Communicate

Slide 50

Slide 50 text

Who do you work with?

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Team You always work 
 in a

Slide 53

Slide 53 text

Team » Communication

Slide 54

Slide 54 text

Coding Standards

Slide 55

Slide 55 text

Drupal CSS Coding Standards https://www.drupal.org/ node/1886770

Slide 56

Slide 56 text

Harry Roberts CSS Guidelines http://cssguidelin.es

Slide 57

Slide 57 text

Hugo Giraudel Sass Guidelines http://sass-guidelin.es

Slide 58

Slide 58 text

Comment 
 your code! https://www.flickr.com/photos/rushen/16071372313

Slide 59

Slide 59 text

Team » Communication

Slide 60

Slide 60 text

“code should be 
 self-documenting”

Slide 61

Slide 61 text

/** * Grid container * Must only contain '.cell' children. */ .grid { height: 100%; font-size: 0; white-space: nowrap; }

Slide 62

Slide 62 text

/** * Grid container * Must only contain '.cell' children. */ .grid { height: 100%; /* Remove inter-cell whitespace */ font-size: 0; /* Prevent inline-block cells wrapping */ white-space: nowrap; }

Slide 63

Slide 63 text

/** * Grid container * Must only contain '.cell' children. * 1. Remove inter cell whitespace. * 2. Prevent inline-block cells wrapping */ .grid { height: 100%; font-size: 0; /* 1 */ white-space: nowrap; /* 2 */ }

Slide 64

Slide 64 text

“Don’t make
 me think!” https://www.flickr.com/photos/mugley/2594318333

Slide 65

Slide 65 text

Use strict

Slide 66

Slide 66 text

Be consistent!

Slide 67

Slide 67 text

Lint!

Slide 68

Slide 68 text

1. Think & Decide 2. Communicate 3. Use strict

Slide 69

Slide 69 text

Credits This presentation… 
 …is based on the works of 
 Harry Roberts. @see http://csswizardry.com …is influenced by the talk “Pains in CSS” by Anikó Fejes. @see http://slides.com/anikofejes/ css-programozoknak-4

Slide 70

Slide 70 text

Tamás Hajas Drupal / Web Project Manager Front-end Developer thamas.github.io