Slide 1

Slide 1 text

CSS Pre-processors Harder, Better, Faster, Stronger leanmachine.se ▪ [email protected] ▪ 2013-09-06

Slide 2

Slide 2 text

CSS is dumb!

Slide 3

Slide 3 text

CSS is dumb! Not DRY (Don’t Repeat Yourself)

Slide 4

Slide 4 text

CSS is dumb! Not DRY (Don’t Repeat Yourself) Not Maintainable

Slide 5

Slide 5 text

CSS is dumb! Not DRY (Don’t Repeat Yourself) Not Maintainable Not Readable

Slide 6

Slide 6 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid green; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: green; }

Slide 7

Slide 7 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid green; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: green; } .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } }

Slide 8

Slide 8 text

BETTER CSS SYNTAX NORMAL CSS COMPILER BROWSER

Slide 9

Slide 9 text

LESS lesscss.org .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Sass sass-lang.com .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Stylus learnboost.github.io/stylus .data-table width 700px margin 30px auto background #f8f8f8 tr border 1px solid green td padding 10px &.highlight background green

Slide 10

Slide 10 text

Nice Features: Nesting Variables Mixins Operations

Slide 11

Slide 11 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid green; td { padding: 10px; &.highlight { background: green; } } } } Nesting .data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; }

Slide 12

Slide 12 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .data-table { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid @pink; td { padding: 10px; &.highlight { background: @pink; } } } } Variables

Slide 13

Slide 13 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins

Slide 14

Slide 14 text

.data-table { width: 700px; margin: 30px auto; background: #f8f8f8; } .data-table tr { border: 1px solid #E82C64; } .data-table tr td { padding: 10px; } .data-table tr td.highlight { background: #E82C64; } @pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins ???

Slide 15

Slide 15 text

@pink: #E82C64; @pageWidth: 700px; .reusable-table() { width: @pageWidth; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins

Slide 16

Slide 16 text

@pink: #E82C64; @pageWidth: 700px; .reusable-table(@w:700px) { width: @w; margin: 30px auto; background: #f8f8f8; tr { border: 1px solid black; td { padding: 10px; &.highlight { background: @pink; } } } } .data-table { .reusable-table(); tr { border: 1px solid @pink; } } Mixins

Slide 17

Slide 17 text

@pink: #E82C64; @pageWidth: 700px; @lightPink: lighten(@pink, 20%); .data-table { .reusable-table(); tr { border: 1px solid @lightPink; } } Operations

Slide 18

Slide 18 text

@pink: #E82C64; @pageWidth: 700px; @lightPink: lighten(@pink, 20%); @cellWidth: 200px; @cellPadding: 20px; .data-table { .reusable-table(); tr { border: 1px solid @lightPink; td { width: (@cellWidth - 2*@cellPadding); padding: @cellPadding; } } } Operations

Slide 19

Slide 19 text

A “Design Pattern” for HTML/CSS using pre-processors

Slide 20

Slide 20 text

HTML Content + Style

Slide 21

Slide 21 text

HTML Content CSS Style

Slide 22

Slide 22 text

HTML Content CSS Style • Can’t create a separate “style structure”

Slide 23

Slide 23 text

HTML Content CSS Style • Can’t create a separate “style structure” • Too many classes pollute HTML with style info

Slide 24

Slide 24 text

HTML Content CSS Style ?

Slide 25

Slide 25 text

HTML Content LESS structure.less Mirror HTML structure and tie in styles LESS mixins.less Styles

Slide 26

Slide 26 text

HTML Content LESS structure.less Mirror HTML structure and tie in styles LESS mixins.less Styles LESS reset.less Resets, defaults, variables

Slide 27

Slide 27 text

Workflow

Slide 28

Slide 28 text

Server Web server that compiles automatically JS that compiles on page load App or command line tool

Slide 29

Slide 29 text

Logo Page 1 Page 2 Page 3 The best thing since sliced bread in three easy steps. Step 1 Step 2 Step 3 Heading Cupcake ipsum dolor sit amet pie dessert faworki fruitcake. Bear claw cupcake candy. Powder ice cream muffin sweet. Cupcake sugar plum bear claw chupa chups wafer biscuit chocolate cake chocolate bar. Cotton candy sweet roll carrot cake oat cake gingerbread toffee jelly-o chocolate chocolate cake. Tart chocolate lemon drops jelly-o muffin oat cake. Pudding candy canes wypas candy carrot cake. Pastry wypas tiramisu chocolate. Pudding pastry brownie cupcake soufflé. Macaroon muffin danish dessert jujubes

Slide 30

Slide 30 text

Logo Page 1 Page 2 Page 3 The best thing since sliced bread in three easy steps. Step 1 Step 2 Step 3 Heading Cupcake ipsum dolor sit amet pie dessert faworki fruitcake. Bear claw cupcake candy. Powder ice cream muffin sweet. Cupcake sugar plum bear claw chupa chups wafer biscuit chocolate cake chocolate bar. Cotton candy sweet roll carrot cake oat cake gingerbread toffee jelly-o chocolate chocolate cake. Tart chocolate lemon drops jelly-o muffin oat cake. Pudding candy canes wypas candy carrot cake. Pastry wypas tiramisu chocolate. Pudding pastry brownie cupcake soufflé. Macaroon muffin danish dessert jujubes Exercise Build out this simple page using LESS and the suggested stylesheet design pattern (structure.less, mixins.less, reset.less).

Slide 31

Slide 31 text

leanmachine.se ▪ [email protected] ▪ 2013-09-06