130
CSS a rapidly changing world

CSS: a rapidly changing world

Embed Size (px)

DESCRIPTION

Extended slides from a recent Sydney Port80 presentation. The slides cover three overall topics: 1) a quick timeline of CSS-related events, 2) key events that changed CSS and 3) a discussion on writing better CSS.

Citation preview

Page 1: CSS: a rapidly changing world

CSSa rapidly changing world

Page 2: CSS: a rapidly changing world

PART 1:

a quicktimeline

Page 3: CSS: a rapidly changing world

2001

Page 4: CSS: a rapidly changing world

Browser changes in 2001

Internet Explorer 6 - August 2001Opera 6 - December 2001

Page 5: CSS: a rapidly changing world

Trends from 2001

Using tables for layout, spacer gifs, general hackery

Page 6: CSS: a rapidly changing world

2002

Page 7: CSS: a rapidly changing world

Browser changes in 2002

Firefox 0.1 - September 2002

Page 8: CSS: a rapidly changing world

Highlights from 2002

Wired.net launch - February 2002

Page 9: CSS: a rapidly changing world

Trends from 2002

CSS moves towards “mainstream”

Page 10: CSS: a rapidly changing world

2003

Page 11: CSS: a rapidly changing world

Browser changes in 2003

Safari 1 - January 2003Opera 7 - January 2003

Page 12: CSS: a rapidly changing world

Highlights from 2003

ESPN launch - February 2003CSS Zen Garden - May 2003Listamatic - September 2003Sliding doors - October 2003

Page 13: CSS: a rapidly changing world

Trends from 2003

CSS becoming more mainstream, CSS tutorials everywhere!

Page 14: CSS: a rapidly changing world

2004

Page 15: CSS: a rapidly changing world

Browser changes in 2004

Firefox 1.0 - November 2004

Page 16: CSS: a rapidly changing world

Highlights from 2004

Faux columns - January 2004Resolution dependant layouts - Sep 2004

Page 17: CSS: a rapidly changing world

Trends from 2004

Dealing with IE, CSS hacks

Page 18: CSS: a rapidly changing world

2005

Page 19: CSS: a rapidly changing world

Browser changes in 2005

Safari 2 - April 2003Opera 8 - April 2005Opera 9 - June 2005

Page 20: CSS: a rapidly changing world

Trends from 2005

Still dealing with IE, CSS hacks

Page 21: CSS: a rapidly changing world

2006

Page 22: CSS: a rapidly changing world

Browser changes in 2006

Opera 9 - June 2006Internet Explorer 7 - October 2006Firefox 2.0 - October 2006

Page 23: CSS: a rapidly changing world

Trends from 2006

Still dealing with IE, CSS hacks

Page 24: CSS: a rapidly changing world

2007

Page 25: CSS: a rapidly changing world

Browser changes in 2007

Safari 3 - January 2007

Page 26: CSS: a rapidly changing world

Highlights from 2007

Blueprint - May 2007iPhone launches - June 2007SASS - August 2007

Page 27: CSS: a rapidly changing world

Trends from 2007

Abstracting CSS - (CSS Frameworks)

Page 28: CSS: a rapidly changing world

2008

Page 29: CSS: a rapidly changing world

Browsers changes in 2008

Safari 4 - June 2008Firefox 3.0 - June 2008Chrome 0.2 - October 2008Chrome 1.0 - December 2008

Page 30: CSS: a rapidly changing world

Trends from 2008

Abstracting CSS - (CSS Frameworks)

Page 31: CSS: a rapidly changing world

2009

Page 32: CSS: a rapidly changing world

Browser changes in 2009

Internet Explorer 8 - March 2009Chrome 2.0 - May 2009Chrome 3.0 - October 2009Opera 10 - September 2009

Page 33: CSS: a rapidly changing world

Highlights from 2009

OOCSS - Feb 2009LESS - August 2009

Page 34: CSS: a rapidly changing world

Trends from 2009

CSS3, Web fonts, Polyfills, SASS and LESS

Page 35: CSS: a rapidly changing world

2010

Page 36: CSS: a rapidly changing world

Browser changes in 2010

Chrome 4.0 - January 2010Chrome 5.0 - May 2010Chrome 6.0 - September 2010Chrome 7.0 - October 2010Chrome 8.0 - December 2010Safari 5 - June 2010Opera 11 - December 2010

Page 37: CSS: a rapidly changing world

Highlights from 2010

HTML5 Boilerplate - April 2010Responsive Web Design - May 2010

Page 38: CSS: a rapidly changing world

Trends from 2010

Responsive Web Design, OOCSS

Page 39: CSS: a rapidly changing world

2011

Page 40: CSS: a rapidly changing world

Browser changes in 2011

Chrome 9.0 - February 2011Chrome 10.0 - February 2011Chrome 11.0 - April 2011Chrome 12.0 - June 2011Chrome 13.0 - August 2011Chrome 14.0 - September 2011Chrome 15.0 - October 2011Chrome 16.0 - December 2011

Page 41: CSS: a rapidly changing world

and more...

Internet Explorer 9 - March 2011Firefox 4.0 - March 2011Firefox 5.0 - June 2011Firefox 6.0 - August 2011Firefox 7.0 - September 2011Firefox 8.0 - November 2011Firefox 9.0 - November 2011

Page 42: CSS: a rapidly changing world

Highlights from 2011

SMACSS - September 2011

Page 43: CSS: a rapidly changing world

Trends from 2011

Mobile first, RWD, OOCSS, SMACSS, SASS, LESS

Page 44: CSS: a rapidly changing world

2012

Page 45: CSS: a rapidly changing world

Browser changes in 2012

Chrome 17.0 - February 2012Chrome 18.0 - March 2012Chrome 19.0 - May 2012Chrome 20.0 - June 2012Chrome 21.0 - July 2012Chrome 22.0 - September 2012Chrome 23.0 - November 2012

Page 46: CSS: a rapidly changing world

and more...

Firefox 10.0 - January 2012Firefox 11.0 - March 2012Firefox 12.0 - April 2012Firefox 13.0 - June 2012Firefox 14.0 - June 2012Firefox 15.0 - August 2012Firefox 16.0 - October 2012Firefox 17.0 - November 2012

Page 47: CSS: a rapidly changing world

and more...

Opera 12 - June 2012Safari 6 - July 2012Internet Explorer 10 - October 2012

Page 48: CSS: a rapidly changing world

Trends from 2012

Mobile first, RWD, OOCSS, SMACSS, Rethinking CSS

Page 49: CSS: a rapidly changing world

PART 2:

key events

Page 50: CSS: a rapidly changing world

Key events

Here are some of the key events that have helped to alter the way we build websites.

Page 51: CSS: a rapidly changing world

New browsers

“As hard as it may be for many people to believe, Internet Explorer 6 began the process, allowing designers and developers to move to full CSS.”

New browsers = new possibilities

Page 52: CSS: a rapidly changing world

The beginning of abstracting CSS

Frameworks

“A set of tools, libraries, conventions, and best practices that attempt to abstract routine tasks into generic modules that can be reused.”

Page 53: CSS: a rapidly changing world

More efficient, more effective

CSS3

“CSS3 provides us with a wide range of new tools such as border-radius, gradients, shadows, web-fonts, animations, transforms, transitions and more.”

Page 54: CSS: a rapidly changing world

Real fonts in the browser

Web fonts

“Webfonts are a font format that allows web designers to use real typography online without losing the advantages of live text — dynamic, searchable, accessible content.”

Page 55: CSS: a rapidly changing world

Moving from fixed to fluid

Responsive Web Design

“Responsive design is about creating flexible layouts that can adapt to suit the screen size and/or orientation of any device.”

Page 56: CSS: a rapidly changing world

Fully abstracted CSS

OOCSS

“The purpose of OOCSS is to encourage code reuse and, ultimately, faster and more efficient stylesheets that are easier to add to and maintain.”

Page 57: CSS: a rapidly changing world

Defining architecture & conventions

SMACSS

“SMACSS is more style guide than rigid framework - an attempt to document a consistent approach to site development when using CSS.”

Page 58: CSS: a rapidly changing world

Writing more efficient & powerful CSS

Preprocessors

“Sass is an extension of CSS3, adding nested rules, variables, mixins and selector inheritance.”

Page 59: CSS: a rapidly changing world

PART 3:

writingbetter CSS?

Page 60: CSS: a rapidly changing world

a radical change in practices

Page 61: CSS: a rapidly changing world

The old wayCSS used to be about clean HTML - withe the absolute minimum of classes. Layouts that used too many classes were considered to be suffering from “classitis”.

Page 62: CSS: a rapidly changing world

ProblemsWhile the HTML stayed clean, the CSS was often bloated and inefficient.

Page 63: CSS: a rapidly changing world

The new wayToday, it is about abstracting layouts into reusable modules so that CSS is more lean and efficient. This means that there are more classes inside the HTML.

Page 64: CSS: a rapidly changing world

The benefitsWhile the HTML has additional classes, the CSS remains very lean. Implementation and modification is quicker and more efficient.

Page 65: CSS: a rapidly changing world

setting up your CSS architecture

Page 66: CSS: a rapidly changing world

SMACSSUse SMACSS to set up your overall CSS architecture

1. Base2. Layout3. Modules4. States5. Theme

Page 67: CSS: a rapidly changing world

setting up your naming conventions

Page 68: CSS: a rapidly changing world

Avoid IDsUse classes rather than IDs for styling purposes. Classes are more flexible. Using only classes can reduce cascade issues.

#box { }.box { }

Page 69: CSS: a rapidly changing world

Use dashesSeparate class names with dashes

.box-feature { }

.boxFeature { }

.box_feature { }

Page 70: CSS: a rapidly changing world

Use prefixesUse “pseudo-namespaces” as prefixes - so that related classes can easily be identified.

.box-feature { }

.box-heading { }

.box-body { }

.box-content { }

Page 71: CSS: a rapidly changing world

MeaningfulClass names should be meaningful, so that other developers can understand their purpose.

.bbdy { }

.box-body { }

Page 72: CSS: a rapidly changing world

SemanticWhere possible, class names should be semantic rather than presentational.

.box-blue { }

.box-alt1 { }

Page 73: CSS: a rapidly changing world

look for patterns - overall layout

Page 74: CSS: a rapidly changing world

An example layoutLook at the following example layout. Can you see any patterns (aspects of the design that can be defined into a single concept and then reused)?

Page 75: CSS: a rapidly changing world
Page 76: CSS: a rapidly changing world

Layout patternsThere are some patterns that can be used to define the overall layout, such as:

wide columnnarrow columnmedium column

Page 77: CSS: a rapidly changing world

wide column narrow column

medium column medium column

Page 78: CSS: a rapidly changing world

wide

narrow

medium medium

wide

narrow

Page 79: CSS: a rapidly changing world

Layout rules.col-wide,.col-medium,.col-narrow{! float: left;! margin-right: 10%;}

Page 80: CSS: a rapidly changing world

Layout rules (continued).col-wide { width: 60%; }.col-medium { width: 45%; }.col-narrow { width: 30%; }.col-last { margin-right: 0; }

Page 81: CSS: a rapidly changing world

look for patterns - rows

Page 82: CSS: a rapidly changing world

RowsThere are six distinct rows. These rows can used to clear other page components above and below.

Page 83: CSS: a rapidly changing world

row

row

row

row

row

row

Page 84: CSS: a rapidly changing world

Row module.row{! clear: both;! overflow: hidden;! zoom: 1;! _overflow: visible;}

Page 85: CSS: a rapidly changing world

Row module extendsTwo of these rows have additional characteristics - they have padding and background-color. These two rows can be defined as “extends” - extending the initial module

Page 86: CSS: a rapidly changing world

blue row

pink row

Page 87: CSS: a rapidly changing world

Row module extends.row-alt1,.row-alt2 {! padding: 1em; }

.row-alt1 { ! background: #bfe6ee; }

.row-alt2 { ! background: #edc9e0; }

Page 88: CSS: a rapidly changing world

look for patterns - boxes

Page 89: CSS: a rapidly changing world

BoxesThere are seven boxes with similar characteristics. These could be converted into one overall module.

Page 90: CSS: a rapidly changing world

box box

box

box box

box box

Page 91: CSS: a rapidly changing world

Box module.box{! overflow: hidden;! zoom: 1;! _overflow: visible;! margin-bottom: 1em;}

Page 92: CSS: a rapidly changing world

Box module extendsTwo of these boxes have additional characteristics - they have padding and background-color. These two rows can be defined as “extends” - extending the initial module

Page 93: CSS: a rapidly changing world

yellow box

green box

Page 94: CSS: a rapidly changing world

Box module extends.box-alt1,.box-alt2 {! padding: 1em; }

.box-alt1 { ! background: #fbf49b; }

.box-alt2 { ! background: #bfe6ee; }

Page 95: CSS: a rapidly changing world

creating a highly flexible box module

Page 96: CSS: a rapidly changing world

FlexibleWe need to be able to target - the overall box- an image/object (aligned left or right)- the body content within the box- a possible heading (could be h1-h6)- possibly even the contents itself

Page 97: CSS: a rapidly changing world

box

box-feature box-bodybox-heading

box-content

Page 98: CSS: a rapidly changing world

The classes.box { }.box-feature { }.box-feature-right { }.box-body { }.box-heading { }.box-content { }

Page 99: CSS: a rapidly changing world

Problem 1: widthHow do we make this box module work, even when the widths vary?

Page 100: CSS: a rapidly changing world

wide box narrow box

narrow box

medium box medium box

medium box medium box

Page 101: CSS: a rapidly changing world

Solution 1:The box module has to spread to fit the width of any parent container, so it must not be given it’s own width.

Page 102: CSS: a rapidly changing world

Box.box{! overflow: hidden;! zoom: 1;! _overflow: visible;! margin-bottom: 1em;}

Page 103: CSS: a rapidly changing world

Problem 2: placementThe box must work when placed anywhere within the layout.

Page 104: CSS: a rapidly changing world
Page 105: CSS: a rapidly changing world

Solution 2:The box module must be “location agnostic”. The box should not be defined based on it’s location.

aside .box { }.box { }

Page 106: CSS: a rapidly changing world

Problem 3: alignmentDid you notice that the images could sit at the left or right?

Page 107: CSS: a rapidly changing world

left aligned

right aligned

left aligned

left aligned

left aligned

left aligned

left aligned

Page 108: CSS: a rapidly changing world

Solution 3:The image/object must be able to be modified to float left or right.

Page 109: CSS: a rapidly changing world

Box feature.box-feature{! float: left;! margin-right: .5em;}

Page 110: CSS: a rapidly changing world

Box feature right.box-feature-alt{! float: right;! margin-left: .5em;}

Page 111: CSS: a rapidly changing world

Problem 4: imagesThe box may contain images or objects that have varying widths.

Page 112: CSS: a rapidly changing world

large imagesmall image

medium image

small image

medium image

medium image

medium image

Page 113: CSS: a rapidly changing world

Solution 3:This can be solved using the “box-body” class. This class will wrap around the contents of the box and force it to sit beside the feature image or object, no matter how wide this image or object is.

Page 114: CSS: a rapidly changing world

box-body

Page 115: CSS: a rapidly changing world

Box body.box-body{! overflow: hidden;! zoom: 1;! _overflow: visible;}

Page 116: CSS: a rapidly changing world

Why use “overflow”?Using overflow: hidden is one method that will trigger the block formatting context, which allows a box to sit beside a floated object, without sliding under it or wrapping around it.

Page 117: CSS: a rapidly changing world

overflow: hidden forces the “box-body” class to sit beside

a floated object, no matter how wide.

Page 118: CSS: a rapidly changing world

changing modules

Page 119: CSS: a rapidly changing world

Modules and extendsWe now have some base modules and “extends”.

.row { }

.row-alt1 { }

.row-alt2 { }

.box { }

.box-alt1 { }

.box-alt2 { }

Page 120: CSS: a rapidly changing world

Change?These base module may be used numerous times within a layout. What happens if you want to change a base module to help in some instances?

Page 121: CSS: a rapidly changing world

Rule 1: keep it simpleThe base module should be defined as simply as possible. This means that they are highly flexible.

Page 122: CSS: a rapidly changing world

Rule 2: extend vs modifyBase modules can be extended (with additional “extend “classes), but should never be modified.

Page 123: CSS: a rapidly changing world

A new “extend”If a based module needs to be modified to suit a specific case, it is probably better to create a new module.

Page 124: CSS: a rapidly changing world

some tips when writing CSS

Page 125: CSS: a rapidly changing world

Avoid repetitionAvoid redefining elements throughout your style sheets. How many times do you need to define headings or font-sizes?

h2 { }.intro h2 { }h2 { }

Page 126: CSS: a rapidly changing world

Avoid deep selectorsAvoid deep selectors as these make the cascade unnecessarily complex.

#content #nav ul li a { }

Page 127: CSS: a rapidly changing world

Avoid qualified selectorsAvoid qualified selectors as these are unnecessary.

div.intro {}

Page 128: CSS: a rapidly changing world

Avoid !important While !important may have it’s uses, it should not be used “reactively” (such as helping to solve cascade issues).

.box { margin: 0 !important; }

Page 129: CSS: a rapidly changing world

Avoid undoing stylesIf your CSS is written correctly, you should never have to undo previous rules.

.box { float: left; }

.box-feature { float: none; }

Page 130: CSS: a rapidly changing world

Russ WeakleyMax Design

Site: maxdesign.com.auTwitter: twitter.com/russmaxdesignSlideshare: slideshare.net/maxdesignLinkedin: linkedin.com/in/russweakley