Slide 1

Slide 1 text

Futureproof styling 
 in Drupal (8) by Tamás Hajas

Slide 2

Slide 2 text

more than 
 200
 .css files in Drupal 8 (currently)

Slide 3

Slide 3 text

There is NO One Right Way!

Slide 4

Slide 4 text

There is NO One Right Way!

Slide 5

Slide 5 text

Tamás Hajas Drupal Consultant Integral Vision Kft

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Team You always work 
 in a

Slide 8

Slide 8 text

Team » Communication

Slide 9

Slide 9 text

Coding Standards

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Harry Roberts CSS Guidelines http://cssguidelin.es

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)

Slide 14

Slide 14 text

CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Team » Communication

Slide 17

Slide 17 text

“code should be 
 self-documenting”

Slide 18

Slide 18 text

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

Slide 19

Slide 19 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 20

Slide 20 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 21

Slide 21 text

Source: Sevens’s button.css

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

Component

Slide 26

Slide 26 text

Component Atom, Molecule… Atomic Design Module SMACSS Object OOCSS Block BEM

Slide 27

Slide 27 text

BEM

Slide 28

Slide 28 text

Block Element Modifier

Slide 29

Slide 29 text

John Albin: Managing complex projects with design components Block

Slide 30

Slide 30 text

John Albin: Managing complex projects with design components Element

Slide 31

Slide 31 text

John Albin: Managing complex projects with design components Modifier

Slide 32

Slide 32 text

„Class names should communicate useful information to developers.” 
 – Nicolas Gallagher About HTML Semantics and Front-End Architecture

Slide 33

Slide 33 text

Proposal: A Style Guide for Seven Progress bar component

Slide 34

Slide 34 text

CSS architecture (for Drupal 8) Progress bar component
Uploading sunset.jpg
Uploaded 221 of 762KB
29%
cancel

Slide 35

Slide 35 text

CSS architecture (for Drupal 8) Progress bar component /** * Progress Bar component */ .progress {} .progress__track {} .progress__bar {} .progress__description {} .progress__cancel {} .progress__cancel:focus, .progress__cancel:hover {} /** * Progress Bar small variant */ .progress--small .progress__track {} .progress--small .progress__bar {} .progress--small .progress__cancel {}

Slide 36

Slide 36 text

Source: Bartik theme Pager in Bartik

Slide 37

Slide 37 text

Source: Bartik’s pager.css Pager in Bartik

Slide 38

Slide 38 text

CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)

Slide 39

Slide 39 text

SMACSS See purecss.io for kind of an implementation

Slide 40

Slide 40 text

SMACSS structure • Base ul { list-style-type: none; padding: 0; margin: 0; }

Slide 41

Slide 41 text

SMACSS structure • Base • Layout .layout-content {} .col-md-6 {}

Slide 42

Slide 42 text

SMACSS structure • Base • Layout • Module

Slide 43

Slide 43 text

SMACSS structure • Base • Layout • Module • State

Slide 44

Slide 44 text

John Albin: Managing complex projects with design components State

Slide 45

Slide 45 text

John Albin: Managing complex projects with design components .flover:hover {} State

Slide 46

Slide 46 text

@media "print" { .flover {} } John Albin: Managing complex projects with design components State

Slide 47

Slide 47 text

SMACSS structure • Base • Layout • Module • State • Theme .install-page { background-color: #1275b2; … }

Slide 48

Slide 48 text

SMACSS-like structure • Base • Layout • Module • State • Theme

Slide 49

Slide 49 text

SMACSS-like structure • Base • Layout • Component Module • State • Theme

Slide 50

Slide 50 text

• Base • Layout • Component = Block • Element • Modifier • State • Theme John Albin: Managing complex projects with design components

Slide 51

Slide 51 text

CSS files for Drupal 8 themes

Slide 52

Slide 52 text

• base.css • layout.css • components.css
 (components, -state, -theme) CSS files for Drupal 8 themes

Slide 53

Slide 53 text

base • elements.css • print.css • typography.css layout • layout.css • node-add.css components • buttons.css • tabs.css • … theme • install-page.css • maintenance
 -page.css CSS files for Drupal 8 themes Source: Drupal 8 Seven theme Bartik refactor meta issue: https://www.drupal.org/node/1342054

Slide 54

Slide 54 text

CSS files for Drupal 8 modules

Slide 55

Slide 55 text

• module_name.module.css 
 (layout, component, state) • module_name.theme.css • module_name.admin.css 
 (layout, component, state) • module_name.admin.theme.css • module_name.base.css CSS files for Drupal 8 modules Modules refactor issue: https://www.drupal.org/node/1995272

Slide 56

Slide 56 text

# Stylesheets override # Remove not used stylesheets Change record: https://drupal.org/node/1876600 stylesheets-override: - system.theme.css stylesheets-remove: - node.module.css mysubtheme.info.yml

Slide 57

Slide 57 text

CSS formatting guidelines CSS file organization (for Drupal 8) CSS architecture (for Drupal 8) [META] Architect our CSS – http://drupal.org/node/1921610

Slide 58

Slide 58 text

There is NO One Right Way!

Slide 59

Slide 59 text

Tamás Hajas Drupal consultant Integral Vision Ltd integralvision.hu about.me/tamashajas