Slide 1

Slide 1 text

The Future of Style Sheets The Future of Style Sheets Bret Little - @little_bret http://bretlittle.surge.sh http://slides.com/bretlittle/future-of-css

Slide 2

Slide 2 text

Web App Crappy-code-o-meter Crappiness

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Is the code readable? Is it easy to change or extend? Is it decoupled from other parts of the application? Will it scale? Is it good? http://engineering.appfolio.com/2012/11/16/css-architecture/

Slide 5

Slide 5 text

Predictable Reusable Maintainable Scalable Good CSS Architecture

Slide 6

Slide 6 text

http://alistapart.com/column/what-will-save-us-from-the-dark-side-of-pre-processors

Slide 7

Slide 7 text

http://benfrain.com/breaking-up-with-sass-postcss/

Slide 8

Slide 8 text

The Dark side of LESS / Sass The Dark side of LESS / Sass Overzealous @extend Unrestrained Nesting Too easy to do the wrong thing Brevity vs Understanding

Slide 9

Slide 9 text

PostCSS CSS Plugin Plugin Stringifier New CSS Parser Source: http://ai.github.io/about-postcss

Slide 10

Slide 10 text

var postcss = require('postcss'); module.exports = postcss.plugin('PLUGIN_NAME', function (opts) { opts = opts || {}; // Work with options here return function (css, result) { // Transform CSS AST here }; }); PostCSS Plugin

Slide 11

Slide 11 text

PostCSS Plugins postcss-nested postcss-mixins autoprefixer cssnext CSS Modules postcss-colorblind postcss-bem-linter css-colorguard postcss-style-guide

Slide 12

Slide 12 text

CSS 4

Slide 13

Slide 13 text

CSS Variables /** Define your vars **/ :root { --main-color: #06c; --accent-color: #006; } .main-heading { color: var(--main-color); } .main-heading__border { color: var(--accent-color); } https://github.com/postcss/postcss-custom-properties

Slide 14

Slide 14 text

Custom Selectors /** Define the selector **/ @custom-selector :--heading h1, h2, h3, h4, h5, h6; /** Use the selector **/ :--heading { font-family: 'Open Sans', sans-serif; } https://github.com/postcss/postcss-custom-selectors

Slide 15

Slide 15 text

Custom Media Queries /** custom query definition **/ @custom-media --small-viewport (max-width: 30em); /** custom query usage **/ @media (--small-viewport) { .hero-image { display: block; } } https://github.com/postcss/postcss-custom-media

Slide 16

Slide 16 text

Color Transformations .block__element { color: color(red a(10%)); background-color: color(red lightness(50%)); border-color: color(hsla(125, 50%, 50%, .4) saturation(+ 10%)); } https://github.com/postcss/postcss-color-function

Slide 17

Slide 17 text

Conic Gradients https://github.com/jonathantneal/postcss-conic-gradient .pie-chart { background: conic-gradient(yellowgreen 32%, gold 0 73%, #f06 0); border-radius: 50%; } .splash { background: #0ac; repeating-conic-gradient(hsla(0,0%,100%,.2) 0 15deg, hsla(0,0%,100%,0) 0 30deg); }

Slide 18

Slide 18 text

Hex Alpha /** #RRGGBBAA or #RGBA syntax **/ h1 { color: #09A23CCC; /** color: rgba(9, 162, 60, .8); **/ } h2 { color: #093C; /** color: rgba(0, 153, 51, .8); **/ } https://github.com/postcss/postcss-color-hex-alpha

Slide 19

Slide 19 text

:any-link a:any-link { color: #4285f4; text-decoration: none; } /** compiles / equivalent to: **/ a:link, a:visited { color: #4285f4; text-decoration: none; } https://github.com/jonathantneal/postcss-pseudo-class-any-link

Slide 20

Slide 20 text

:matches p:matches(:first-child, .special) { color: red; } /** compiles / equivalent to: **/ p:first-child, p.special { color: red; } https://github.com/postcss/postcss-selector-matches

Slide 21

Slide 21 text

:not p:not(:first-child, .special) { color: red; } /** compiles / equivalent to: **/ p:not(:first-child), p:not(.special) { color: red; } https://github.com/postcss/postcss-selector-not

Slide 22

Slide 22 text

BEM CSS .app-widgets__grid-row { position: relative; bottom: 20px; } .app-widgets__grid-row--active { background: red; } https://css-tricks.com/bem-101/

Slide 23

Slide 23 text

BEM CSS == JS Globals .app-widgets__grid__row--active { position: relative; bottom: 20px; } window.app = window.app || {}; window.app.widgets = window.app.widgets || {}; window.app.widgets.grid = window.app.widgets.grid || {}; window.app.widgets.grid.render = function() { /** code **/ }

Slide 24

Slide 24 text

/** app.js **/ import grid from './grid.js'; grid.render(); /** grid.js **/ export default { render: function() { /** **/ } } JavaScript Modules

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

CSS Modules /** Button.css **/ .a { composes: aLink from './Link.css'; display: block; padding: 0 15px; } /** Link.css **/ .aLink { text-decoration: none; cursor: pointer; color: #ffab40; } /** Button.js **/ import styles from './Button.css'; export default function() { return ( } This is my button! ) .Button__a__1olur { text-decoration: none; cursor: pointer; color: #ffab40; display: block; padding: 0 15px; }

Slide 27

Slide 27 text

http://adventurous-bait.surge.sh/ http://materializecss.com/ https://github.com/blittle/stars

Slide 28

Slide 28 text

Thank You Thank You https:/ /slides.com/bretlittle/future-of-css https:/ /slides.com/bretlittle/future-of-css @little_bret @little_bret