Slides of my Drupal Dev Days Montpellier 2015 session. http://montpellier2015.drupaldays.org/sessions/futureproof-styling-drupal
Futureproof styling in Drupal (8)by Tamás Hajas
View Slide
more than 200 .css files in Drupal 8 (currently)
There is NOOne Right Way!
Tamás HajasDrupal ConsultantIntegral Vision Kft
TeamYou always work in a
Team » Communication
Coding Standards
Drupal CSSCoding Standardshttps://www.drupal.org/node/1886770
Harry RobertsCSS Guidelineshttp://cssguidelin.es
Hugo GiraudelSass Guidelineshttp://sass-guidelin.es
CSS formatting guidelinesCSS architecture (for Drupal 8)CSS file organization (for Drupal 8)
Comment your code!https://www.flickr.com/photos/rushen/16071372313
“code should be self-documenting”
/*** 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
“Don’t make me think!”https://www.flickr.com/photos/mugley/2594318333
Keep specificity low!https://www.flickr.com/photos/freetheimage/14741164059
Component
ComponentAtom, Molecule…Atomic DesignModuleSMACSSObjectOOCSSBlockBEM
BEM
BlockElementModifier
John Albin: Managing complex projects with design componentsBlock
John Albin: Managing complex projects with design componentsElement
John Albin: Managing complex projects with design componentsModifier
„Class names should communicateuseful information to developers.” – Nicolas GallagherAbout HTML Semantics and Front-End Architecture
Proposal: A Style Guide for SevenProgress bar component
CSS architecture (for Drupal 8)Progress bar componentUploading sunset.jpgstyle="width: 29%">Uploaded 221 of 762KB29%cancel
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 themePager in Bartik
Source: Bartik’s pager.cssPager in Bartik
SMACSSSee purecss.io for kind of an implementation
SMACSS structure• Base ul {list-style-type: none;padding: 0;margin: 0;}
SMACSS structure• Base• Layout .layout-content {}.col-md-6 {}
SMACSS structure• Base• Layout• Module
SMACSS structure• Base• Layout• Module• State
John Albin: Managing complex projects with design componentsState
John Albin: Managing complex projects with design components.flover:hover {}State
@media "print" {.flover {}}John Albin: Managing complex projects with design componentsState
SMACSS structure• Base• Layout• Module• State• Theme.install-page {background-color: #1275b2;…}
SMACSS-like structure• Base• Layout• Module• State• Theme
SMACSS-like structure• Base• Layout• Component Module• State• Theme
• Base• Layout• Component = Block• Element• Modifier• State• ThemeJohn Albin: Managing complex projects with design components
CSS files for Drupal 8themes
• base.css• layout.css• components.css (components, -state, -theme)CSS files for Drupal 8 themes
base• elements.css• print.css• typography.csslayout• layout.css• node-add.csscomponents• buttons.css• tabs.css• …theme• install-page.css• maintenance -page.cssCSS files for Drupal 8 themesSource: Drupal 8 Seven theme Bartik refactor meta issue: https://www.drupal.org/node/1342054
CSS files for Drupal 8modules
• 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.cssCSS files for Drupal 8 modulesModules refactor issue: https://www.drupal.org/node/1995272
# Stylesheets override# Remove not used stylesheetsChange record: https://drupal.org/node/1876600stylesheets-override:- system.theme.cssstylesheets-remove:- node.module.cssmysubtheme.info.yml
CSS formatting guidelinesCSS file organization (for Drupal 8)CSS architecture (for Drupal 8)[META] Architect our CSS – http://drupal.org/node/1921610
Tamás HajasDrupal consultantIntegral Vision Ltdintegralvision.huabout.me/tamashajas