revamp your stylesheet

29
Revamp Your Stylesheets Gary Homidas UX Designer and Front-end Developer [email protected]

Upload: gary-homidas

Post on 14-Apr-2017

174 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Revamp Your Stylesheet

Revamp Your Stylesheets

Gary HomidasUX Designer and Front-end [email protected]

Page 2: Revamp Your Stylesheet

What’s the point?The beauty of it all. You can write standard CSS and begin to use the features of the preprocessor as you work. Your code will become more complex as your knowledge grows.

It is a time saver…. seriously!

Page 3: Revamp Your Stylesheet

• What’s wrong with your CSS?

• Learn the fundamentals

• Play with Code

• 3rd Party Tools

Online Editors:

• LESS: http://lesscss.org/less-preview/

• SASS: http://www.sasseditor.xyz/

Objectives

Page 4: Revamp Your Stylesheet

What’s wrong with your CSS? She becomes too high maintenance (updating colors,

images, fonts, etc.) Redundant selectors Lengthier document Vendor prefixes

Page 5: Revamp Your Stylesheet

Similarities between LESS and SASS∎ Variables∎ Mixins∎ Nesting∎ Functions∎ Import∎ Conditional / Comparison

Operators∎ Loops∎ 3rd Party Tools

Learning the Fundamentals

Page 6: Revamp Your Stylesheet

Variablesa + 4 = 7When a = 3

Just like you’ve learned in school!

Page 7: Revamp Your Stylesheet

• Makes reusing code easy• Can be treated like a variable or function.• Can include CSS selectors and their attributes (nested

Classes/ID's)• Great way to print different attributes based on a situation

Blending things togetherMixins

Page 8: Revamp Your Stylesheet

• Pass arguments and include conditional statements and loops

• Accept “named parameters” (LESS) or “keyword Arguments” (SASS) where you can explicitly designate which argument to satisfy

• LESS allows you to declare multiple mixins with the same name and accepting different number of arguments

Mixins

Page 9: Revamp Your Stylesheet

∎ Allows coder to visualize the selector’s hierarchy

∎ Minimizes scrolling throughout the file and reduces the size of your CSS file

Nesting

Page 10: Revamp Your Stylesheet

The key here is “program” with flexibility in mind

Page 11: Revamp Your Stylesheet

∎ Pass values to your mixin/function for a more of dynamic stylesheet

∎ LESS uses mixins as functions

∎ SASS can use either mixins or actual functions

∎ Both can be used to return a value

Functions“Program” with flexibility in mind

Page 12: Revamp Your Stylesheet

∎ LESS returns values by assigning the results into a variable

∎ SASS has the “return” keyword

∎ SASS function returns single value of any SASS data type, including: numbers, strings, colors, booleans, or lists.

Functions

Page 13: Revamp Your Stylesheet

∎ Allows the author to include other stylesheets into project.

∎ Compartmentalize your styles while reducing http requests

∎ Both will merge files with their respective file extension into a single CSS

file.

∎ Both treat files with the CSS extension as a normal CSS import

Import

Page 14: Revamp Your Stylesheet

LESS Exception: You can import a CSS file directly into the LESS file using the @import (inline) directive (one http request). See Examples

SASS allows you to import multiple files w/ one import SASS: some circumstances where the traditional import

will be used are as follows: If the @import has any media queries, url, and othersSee Examples

Import

Page 15: Revamp Your Stylesheet

CONDITIONAL STATEMENTSOnly add specific styles under

certain situations. For example, if a statement is true, execute a

code.

COMPARRISON OPERATORSCompare arguments and execute

code based on the items. For example, when a text color is

dark, change to a light background color

Logical Operators

Page 16: Revamp Your Stylesheet

LESS calls them “Mixin Guards” LESS tries to stick to the declarative nature of CSS Uses “when” to compare Traditional comparison operators: >, >=, =, =<, <, true

(doesn’t use false) Other keywords: ‘AND’, ‘isnumber’, ‘not’

Logical Operators - LESS

Page 17: Revamp Your Stylesheet

Traditional programming conditional and comparative statements;

@if, @else, and, or, not

>, >=, =, =<, <,

Note: and, or, not are written verbatim. Boolean values: True or False

Logical Operators - SASS

Page 18: Revamp Your Stylesheet

Work smarter not harder.Effectively using loops

Page 19: Revamp Your Stylesheet

Repeat parts of your code. Create column grids Create new CSS selectors LESS: recursive mixins (mixins can “call” themselves) SASS: resemble traditional programming keywords

@for, @each, @while,

LoopsLet the computer handle redundancy

Page 20: Revamp Your Stylesheet

3’rd Party ToolsLet someone else do the heavy lifting

Page 21: Revamp Your Stylesheet

3’rd Party Tools

∎ Allow automatic vender prefix update via Can I Use∎ Extensive Mixin library with documentation∎ Helper Functions∎ Generate Image Sprites∎ Asset urls (i.e.. http_path, image-url, etc.)∎ Typography (vertical rhythm)

Sass Supporters: Compass

Page 22: Revamp Your Stylesheet

3’rd Party Tools

∎ Very Lightweight with tons of mixins∎ Simpler font-face declarations∎ Helpers aka (Add-ons)∎ Timing Functions

Sass Supporters: Bourbon

Page 23: Revamp Your Stylesheet

3’rd Party Tools

∎ Cross-browser CSS-prefix∎ Automatic LESS updater∎ Easy Drag-n-Drop project setup∎ Inconsistent debugger

LESS Supporters: SimpLESS

Page 24: Revamp Your Stylesheet

3’rd Party Tools

∎ Easy to use ∎ Automatically watch your LESS files after the first

crunch!∎ Comes standard with an IDE (only uses HTML, CSS,

JS, PHP, LESS)∎ Debugger (informs you of where errors are but not

too detailed on why it’s an error. □ I.e.. passing too many arguments to a mixin: it will

say “runtime” error

LESS Supporters: Crunch 2 (Free version)

Page 25: Revamp Your Stylesheet

3’rd Party Tools

∎ Easy Drag-n-Drop project setup∎ Use globally installed less (instead of what’s

bundled with WinLESS)∎ Automatically compile LESS files on change.∎ Debugging is easier with more descriptive error

messages

LESS Supporters: WinLESS

Page 26: Revamp Your Stylesheet

3’rd Party Tools

∎ Comprehensive Mixin libraries with 86 Mixins∎ Unlimited number of shadows, gradients,

animations, etc.∎ Well documented with real code examples∎ Animations uses cubic-bezier timing functions

LESS Supporters: LESS Hat

Page 27: Revamp Your Stylesheet

3’rd Party Tools

∎ Codekit (Mac only)∎ Koala

Dual Supporters

Page 28: Revamp Your Stylesheet

Check Them Out

∎ Scott Kellum Color-Schemer: https://github.com/at-import/color-schemer

∎ Sass Bites (YouTube)∎ Scott Level Up Tuts

http://leveluptuts.com/

Page 29: Revamp Your Stylesheet

THANKS!Any questions?

Linkedin:gary homidasEmail: [email protected]