Futureproof styling in Drupal (8)
by Tamás Hajas
Futureproof styling in Drupal (8) by Tams Hajas more than 200 - - PowerPoint PPT Presentation
Futureproof styling in Drupal (8) by Tams Hajas more than 200 .css files in Drupal 8 (currently) There is NO One Right Way! There is NO One Right Way! Tams Hajas Drupal Consultant Integral Vision Kft You always work in
by Tamás Hajas
more than
.css files in Drupal 8 (currently)
Tamás Hajas
Drupal Consultant
Integral Vision Kft
You always work in a
https://www.drupal.org/ node/1886770
Harry Roberts
http://cssguidelin.es
Hugo Giraudel
http://sass-guidelin.es
CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)
CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)
https://www.flickr.com/photos/rushen/16071372313
/** * Grid container * Must only contain '.cell' children. */ .grid { height: 100%; font-size: 0; white-space: nowrap; }
/** * 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; }
/** * 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 */ }
Source: Sevens’s button.css
https://www.flickr.com/photos/mugley/2594318333
CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)
https://www.flickr.com/photos/freetheimage/14741164059
Atom, Molecule…
Atomic Design
Module
SMACSS
Object
OOCSS
Block
BEM
<div class="flower__bed"> <div class="flower"> <div class="flower__petals"> <div class="flower__face"></div> </div> <div class="flower__stem"> <div class="flower__leaves"></div> </div> </div> </div>
John Albin: Managing complex projects with design components
Block
<div class="flower__bed"> <div class="flower"> <div class="flower__petals"> <div class="flower__face"></div> </div> <div class="flower__stem"> <div class="flower__leaves"></div> </div> </div> </div>
John Albin: Managing complex projects with design components
Element
<div class="flower__bed"> <div class="flower flower--tulip"> <div class="flower__petals"> <div class="flower__face"></div> </div> <div class="flower__stem"> <div class="flower__leaves"></div> </div> </div> </div>
John Albin: Managing complex projects with design components
Modifier
„Class names should communicate useful information to developers.”
– Nicolas Gallagher
About HTML Semantics and Front-End Architecture
Proposal: A Style Guide for Seven
Progress bar component
CSS architecture (for Drupal 8)
Progress bar component
<div class="progress progress--small"> <label class="label label--small">Uploading sunset.jpg</label> <div class="progress__track"> <div class=“progress__bar js-progress-percent“ style="width: 29%"></div> </div> <div class="progress__description"> <div class="layout-pull">Uploaded 221 of 762KB</div> <strong class="layout-push">29%</strong> </div> <a class="progress__cancel" href="#" title="cancel"> <span class="visually-hidden">cancel</span> </a> </div>
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 {}
Source: Bartik theme
Pager in Bartik
Source: Bartik’s pager.css
Pager in Bartik
CSS formatting guidelines CSS architecture (for Drupal 8) CSS file organization (for Drupal 8)
See purecss.io for kind of an implementation
SMACSS structure
ul { list-style-type: none; padding: 0; margin: 0; }
SMACSS structure
.layout-content {} .col-md-6 {}
SMACSS structure
SMACSS structure
<div class="flower is-pollinating">
John Albin: Managing complex projects with design components
State
John Albin: Managing complex projects with design components
.flover:hover {} State
@media "print" { .flover {} }
John Albin: Managing complex projects with design components
State
SMACSS structure
.install-page { background-color: #1275b2; … }
SMACSS-like structure
SMACSS-like structure
John Albin: Managing complex projects with design components
(components, -state, -theme)
CSS files for Drupal 8 themes
base
layout
components
theme
CSS files for Drupal 8 themes
Source: Drupal 8 Seven theme Bartik refactor meta issue: https://www.drupal.org/node/1342054
(layout, component, state)
(layout, component, state)
CSS files for Drupal 8 modules
Modules refactor issue: https://www.drupal.org/node/1995272
# Stylesheets override # Remove not used stylesheets
Change record: https://drupal.org/node/1876600
stylesheets-override:
stylesheets-remove:
mysubtheme.info.yml
CSS formatting guidelines CSS file organization (for Drupal 8) CSS architecture (for Drupal 8)
[META] Architect our CSS – http://drupal.org/node/1921610
Drupal consultant
Integral Vision Ltd integralvision.hu about.me/tamashajas