Style Your Site Part 1

30
Style Your Site A Comprehensive CSS Design Tutorial Ben MacNeill User Interface Designer, eXtension at NCSU http://commons.wikimedia.org/wiki/File:SkeletonsNumbers.png

description

(Part 1 of 2) Cascading Style Sheets (CSS) control the look and feel of modern web pages while also separating presentation from content. Learn comprehensive CSS techniques in this step-by-step coding demonstration that starts with an un-styled web page and ends up with a finished design. This presentation will also touch on accessibility, semantic markup, visual design and other site-design related issues.

Transcript of Style Your Site Part 1

Page 1: Style Your Site Part 1

Style Your SiteA Comprehensive CSS Design Tutorial

Ben MacNeillUser Interface Designer, eXtension at NCSU

http://commons.wikimedia.org/wiki/File:SkeletonsNumbers.png

Page 2: Style Your Site Part 1

What is CSS?

Page 3: Style Your Site Part 1
Page 4: Style Your Site Part 1
Page 5: Style Your Site Part 1

What is CSS?

Page 6: Style Your Site Part 1

document content

document presentation

Why Use CSS?

Page 7: Style Your Site Part 1

Some real reasons

• Accessibility (Section 508 anyone?)

• Reduce complexity/repetition in the markup

• The Cosmetic stuff is all in one place. Global design changes are easy.

• Your content is more portable for mobile devices, feed readers, printing

• It's not 1999

Page 8: Style Your Site Part 1

Laying the Ground Work

Simple, semantic html markup

creates good structure

Page 9: Style Your Site Part 1

TABLES

ARE FOR DATA

NOT FOR LAYOUT

Page 10: Style Your Site Part 1

CSS Syntax

h1 {font-size: 1.5em}

selectors

properties

values

Page 11: Style Your Site Part 1

CSS Selectors

div

div#feature

div.comment

div#feature.audio

type selector

ID selector

Class selector

ID + Class

Page 12: Style Your Site Part 1

First Session• Fixed-width layout

• Flexible, bulletproof text-based navigation

• Light design styling

• Print stylesheet (if time)

Page 13: Style Your Site Part 1

Second Session

• CSS-based image sprites & background images

• Fluid layout

• Font control

• CSS reset stylesheet

• Convert form to semantic markup and style it

• Mobile stylesheet for the iPhone

The Enhancing

Page 14: Style Your Site Part 1

Let’s Go to the Browser

Page 15: Style Your Site Part 1

Important Concepts(Visual formatting model)

Page 16: Style Your Site Part 1

The Display Property

Block-level elements:<p>, <ul>, <div>

Every html element has a default display: property

Inline-level elements:<em>, <span>

Page 17: Style Your Site Part 1

The Display Property

Block-level elements are formatted visually as blocks.

Inline-level elements are formatted visually as lines.

Page 18: Style Your Site Part 1

The Cascade

• Each style rule (the selector) is assigned a weight

• Most specific selector (greatest weight) wins

div {color: red;}div div {color: blue;} div div div {color: green;}

Page 19: Style Your Site Part 1

Winning the Cascade

• Most specific selector wins

• If two selectors are equal, last one wins

• inline styles beat style sheets

• !important beats everything

Page 20: Style Your Site Part 1

All Elements Are Not Equal

• Classes and IDs carry more weight or specificity

div pdiv.feature pdiv#article pdiv#article.feature p

Page 21: Style Your Site Part 1

The Box Model

http://www.flickr.com/photos/31288116@N02/3065654591/

Page 22: Style Your Site Part 1

Width != Width

Page 23: Style Your Site Part 1

Shorthand

margin: 10px;

margin: 10px 20px 30px 10px;

margin: 10px 20px;

margin: 10px 20px 20px;

top right bottom left

top sides bottom

top/bottom sides

all

Page 24: Style Your Site Part 1

Floating

• Floated elements are taken out of the normal document flow and shifted to the left or right as far as it can go

• elements following floated elements shift up and wrap unless cleared with the clear: property

Page 25: Style Your Site Part 1

Tools & Testing

• Firebug http://getfirebug.com/

• Web Developer Toolbar by Chris Pederick (Firefox)http://chrispederick.com/work/web-developer/

• Target: Firefox > Safari > IE8 > IE7

Page 26: Style Your Site Part 1

Tip: Firebug can help with the Box Model

Page 27: Style Your Site Part 1

• CSS Selectors Cheat Sheet: www.cameronmoll.com/articles/widget/cheatsheet.pdf

Page 28: Style Your Site Part 1

• Better Font Stack: http://unitinteractive.com/blog/2008/06/25/better-css-font-stacks/

Page 29: Style Your Site Part 1

August 27, 2001IE6 released

8

http://www.stopie6.org/

Page 30: Style Your Site Part 1

Thanks!

Ben MacNeillUser Interface Designer, eXtension at [email protected]

Slides and zipped Code examples:http://www.slideshare.net/chillnchttp://drop.io/benmacneill

My CSS bookmarks:http://del.icio.us/chillnc/css