css systems

78
WRITING MAINTAINABLE CSS Natalie Downe | Barcamp London 5 28th September 2008 1

Upload: natalie-downe

Post on 08-Sep-2014

101 views

Category:

Technology


0 download

DESCRIPTION

http://natbat.net/2008/Sep/28/css-systems/ - A CSS System is a reusable set of content-oriented markup patterns and associated CSS created to express a site's individual design. It is the end result of a process that emphasizes up-front planning, loose coupling between CSS and markup, pre-empting browser bugs and overall robustness. It also incorporates a shared vocabulary for developers to communicate the intent of the code. This talk elaborates on this concept, and also describes a number of tricks I use to pre-empt maintainability issues. Originally presented at BarCamp London 5 in Richmond on the 28th of September 2008.

TRANSCRIPT

Page 1: CSS Systems

WRITING MAINTAINABLE CSSNatalie Downe | Barcamp London 5

28th September 2008

1

Page 2: CSS Systems

WRITING MAINTAINABLE CSSNatalie Downe | Barcamp London 5

28th September 2008

2

Page 3: CSS Systems

CSS SYSTEMSNatalie Downe | Barcamp London 5

28th September 2008

3

Page 4: CSS Systems

I am an optimist

4

Page 5: CSS Systems

so I am going to assume that

5

Page 6: CSS Systems

you already write beautiful and valid markup

6

Page 7: CSS Systems

you use semantic markup & class / id names

7

Page 8: CSS Systems

you separate content, presentation & behavior

8

Page 9: CSS Systems

because you care

9

Page 10: CSS Systems

Maintainability in CSS?

10

Page 11: CSS Systems

It’s not a solved problem.

11

Page 12: CSS Systems

It’s not just about the future

12

Page 13: CSS Systems

It’s about now

13

Page 14: CSS Systems

CLEARLEFT

High quality code

To tight deadlines

For handover to external developers

14

Page 15: CSS Systems

CSS SYSTEMS

15

Page 16: CSS Systems

A CSS SYSTEM IS...

a top down approach

personalised for an individual site

a reusable set of markup patterns and CSS

looking at the overall stucture and individual components

glossary of shared vocabulary for developers

16

Page 17: CSS Systems

ORDERING

Rule blocks are loosely ordered by specificity,

Elements, grouped by type of tag

Classes, grouped by the effect they create

IDs, grouped by the component they affect

17

Page 18: CSS Systems

GROUPING

general stylesbody stylesresetlinks headingsother elements, tags

helper stylesformsnotifications and errorsconsistant items with normally just one class

page structureskeleton including page furniture,

page componentsmost of your styles will be in here

overrides

18

Page 19: CSS Systems

GROUPING

general stylesbody stylesresetlinks headingsother elements, tags

helper stylesformsnotifications and errorsconsistant items with normally just one class

page structureskeleton including page furniture,

page componentsmost of your styles will be in here

overrides

19

Page 20: CSS Systems

CSS Editmacrabbit.com/cssedit

20

Page 21: CSS Systems

CSS Editmacrabbit.com/cssedit

21

Page 22: CSS Systems

CONDITIONAL COMMENTS

Never use browser hacks

Browser specific stylesheets for all versions of IE and another for IE6 and under

If you have to entirely re-engineer for IE, overriding your standards ready CSS in a conditional comment, you’re Doing It Wrong

22

Page 23: CSS Systems

please look to my right

for a moment

23

Page 24: CSS Systems

please look to my right

for a moment

24

Page 25: CSS Systems

BEFORE YOU STARTSo I have a design ... what now?

25

Page 26: CSS Systems

look at the basics

26

Page 27: CSS Systems

will it be liquid? elastic? or fixed?

27

Page 28: CSS Systems

MAINTAINABLE LAYOUT

if you are using an em or fixed width layout, try to only set a width on the container, using percentages inside

a max-width of 100% will stop your layout creeping out the side of the viewport

up and down font size all the time

be afraid of heights, vertigo is healthy on the web. NEVER use height in px on anything with text inside

28

Page 29: CSS Systems

29

Page 30: CSS Systems

the grid

30

Page 31: CSS Systems

draw diagrams

31

Page 32: CSS Systems

lots of diagrams

32

Page 33: CSS Systems

make calculations

33

Page 34: CSS Systems

get inventive

34

Page 35: CSS Systems

levels of headings

35

Page 36: CSS Systems

36

Page 37: CSS Systems

page structure and components

37

Page 38: CSS Systems

38

Page 39: CSS Systems

39

Page 40: CSS Systems

40

Page 41: CSS Systems

MAINTAINABILITY MYTHSAny existing ‘best practices’ or approaches?

41

Page 42: CSS Systems

CSS frameworks

42

Page 43: CSS Systems

Single line declaration blocks

43

Page 44: CSS Systems

Selector based indentation

44

Page 45: CSS Systems

colour.css / layout.css / typography.css

45

Page 46: CSS Systems

ON YOUR MARKS ...You have your design and your plan - you’re all set!

46

Page 47: CSS Systems

use the cascade

47

Page 48: CSS Systems

div#page div.teaser ul.products li p.name

48

Page 49: CSS Systems

ul.products p.name

49

Page 50: CSS Systems

you love to float

50

Page 51: CSS Systems

shorthand?

51

Page 52: CSS Systems

p { font: 12px/14px sans-serif }p { font: 80% sans-serif }p { font: x-large/110% "New Century Schoolbook", serif }p { font: bold italic large Palatino, serif }p { font: normal small-caps 120%/120% fantasy }

52

Page 53: CSS Systems

53

Page 54: CSS Systems

background: url("w00t.png") orange 0 50% repeat fixed;

54

Page 55: CSS Systems

background: lime;

55

Page 56: CSS Systems

background: url("rofl.gif");

56

Page 57: CSS Systems

background-color: lime;

background-image: url("rofl.png");

57

Page 58: CSS Systems

PREPARE FOR THE WORSTn00bs will one day be let loose on your code

(accept it)

58

Page 59: CSS Systems

clear your footer

59

Page 60: CSS Systems

careful with dimensions

60

Page 61: CSS Systems

watch your height

61

Page 62: CSS Systems

hooks

62

Page 63: CSS Systems

editable content

63

Page 64: CSS Systems

sanitise text

64

Page 65: CSS Systems

abstract your icons

65

Page 66: CSS Systems

DESIGN TO AVOID DEBUGGINGengineer your way around the browser

66

Page 67: CSS Systems

Simultaneously develop

67

Page 68: CSS Systems

dont re-engineer seperate solutions

68

Page 69: CSS Systems

floating

69

Page 70: CSS Systems

you need to set psuedo selectors on

links

70

Page 71: CSS Systems

buttons

71

Page 72: CSS Systems

review

72

Page 73: CSS Systems

HANDOVERwhat to give the client

73

Page 74: CSS Systems

THE IDEAL HANDOVER INCLUDES

The markup scheme, a set of files demonstrating the different markup components

The CSS itself

Supporting documents that explain the system as clearly as possible

A face to face meeting if possible

74

Page 75: CSS Systems

FINALLY

75

Page 76: CSS Systems

ITS ALL ABOUT THE SYSTEM

define it

develop it

maintain it

communicate it

76

Page 77: CSS Systems

THANK YOU

77

Page 78: CSS Systems

?78