beautiful maintainable css

51
beautiful maintainable css.

Post on 22-Oct-2014

19.618 views

Category:

Technology


0 download

DESCRIPTION

Folks at the Sydney Rails Group asked me how to clean up their CSS and make it easily maintainable. I delivered that message in a way that way that would appeal to them philosophically rather than just show code

TRANSCRIPT

Page 1: Beautiful Maintainable CSS

beautifulmaintainablecss.

Page 2: Beautiful Maintainable CSS

the premise

Separation of the various layers that make up a webpage is a ‘good thing’™

Page 3: Beautiful Maintainable CSS

the premise

Presentation should not be mussed in with structureor behaviour

Page 4: Beautiful Maintainable CSS

the premise

Your HTML needs to be clean, elegant and semantic

Page 5: Beautiful Maintainable CSS

old skool

Anybody still using TABLEs for layout?

Page 6: Beautiful Maintainable CSS

old skool

What about when everything getsa little bit too hard?

Page 7: Beautiful Maintainable CSS

old skool

And you have a

deadline?

Page 8: Beautiful Maintainable CSS

You’re going to

hell!

Page 9: Beautiful Maintainable CSS

old skool

The hell of applying CSS to poor HTML

Page 10: Beautiful Maintainable CSS

clean and shiny

Your HTML should be like your Ruby code ♥Ruby

Page 11: Beautiful Maintainable CSS

clean and shiny

Let’s assume your app has the most glorious HTML ever known to geeks

Page 12: Beautiful Maintainable CSS

clean and shiny

It’s semantically rich

Page 13: Beautiful Maintainable CSS

clean and shiny

It’s human readable

Page 14: Beautiful Maintainable CSS

clean and shiny

It’s

beautiful!

Page 15: Beautiful Maintainable CSS

clean and shiny

Your CSS needs to match up, right?

Page 16: Beautiful Maintainable CSS

some basics

Readability = maintainability

Page 17: Beautiful Maintainable CSS

If people can read your codethey (and you) can work outwhat you thought you were [email protected] morning your client ‘needed’ the code live.

before breakfast.

Page 18: Beautiful Maintainable CSS

readability

Order your rules according to a defined system

Page 19: Beautiful Maintainable CSS

readability

And stick to it!

Page 20: Beautiful Maintainable CSS

readability

Detail that system at the top of the file

Page 21: Beautiful Maintainable CSS

readability

Provide a table of contents

Page 22: Beautiful Maintainable CSS

readability

Use indentingtodenotehierarchy

Page 23: Beautiful Maintainable CSS

inside your rules

Alphabetise your property-value pairs

Page 24: Beautiful Maintainable CSS

inside your rules

It’s a system everybody can recognise

Page 25: Beautiful Maintainable CSS

inside your rules

Maximise use of shorthand

Page 26: Beautiful Maintainable CSS

shorthand

margin-bottom: 0.3em; margin-left: 3em; margin-top: 2em;

Page 27: Beautiful Maintainable CSS

shorthand

margin-bottom: 0.3em; margin-left: 3em; margin-top: 2em;is ugly

Page 28: Beautiful Maintainable CSS

shorthand

margin: 2em 0 0.3em 3em; a

Page 29: Beautiful Maintainable CSS

shorthand

margin: 2em 0 0.3em 3em; is elegant

Page 30: Beautiful Maintainable CSS

shorthand

Plus, defining all properties makes sure you don't missany.

Page 31: Beautiful Maintainable CSS

So now anybodycan read your code...

Let’s make it beautiful

Page 32: Beautiful Maintainable CSS

Isolate your hacks

We all know you’ll need them

Page 33: Beautiful Maintainable CSS

Isolate your hacks

Don’t sully the good code

Page 34: Beautiful Maintainable CSS

Isolate your hacks

Put hacks in separate files

Page 35: Beautiful Maintainable CSS

Some people will tell you that Microsoft's proprietary Conditional Comments are evil and wrong.

Page 36: Beautiful Maintainable CSS

that makes them perfectly suited to dealing with the

evil wrongness...

that is IE’s CSS support.

Page 37: Beautiful Maintainable CSS

and that meansyou can use theproprietary Microsoft

...

CSS Expressions without invalidating your good code.

Page 38: Beautiful Maintainable CSS

The Validatoris your friend.

Page 39: Beautiful Maintainable CSS

use the validator

when you finish significant CSS coding

Page 40: Beautiful Maintainable CSS

use the validator

when you’ve got bugs that don’t make sense

Page 41: Beautiful Maintainable CSS

use the validator

before you migrate code to production

Page 42: Beautiful Maintainable CSS

To summarise...

Page 43: Beautiful Maintainable CSS

semantic

Page 44: Beautiful Maintainable CSS

readable

Page 45: Beautiful Maintainable CSS

hierarchical

Page 46: Beautiful Maintainable CSS

alphabetised

Page 47: Beautiful Maintainable CSS

shorthand-ed?

Page 48: Beautiful Maintainable CSS

valid

Page 49: Beautiful Maintainable CSS

maintainable

Page 50: Beautiful Maintainable CSS

beautiful

Page 51: Beautiful Maintainable CSS

If you get stuck, let me know.I’m always happy to help.

Email: [email protected]: [email protected]: lachlanhardy