class 2: css selectors, classes & ids

42
CLASS 2 CSS: SELECTORS, CLASSES & IDS Web Design, gRAPH-3271-01 Instructor: Erika Tarte Rhode Island School of Design Wintersession 2011

Upload: erika-tarte

Post on 27-Jun-2015

465 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Class 2: CSS Selectors, Classes & Ids

Class 2 Css: seleCtors, Classes & ids

Web Design, gR APH-327 1- 01

Instructor: Erika TarteRhode Island School of DesignWintersession 2011

Page 2: Class 2: CSS Selectors, Classes & Ids

webpage

Page 3: Class 2: CSS Selectors, Classes & Ids

In addition to content, webpages contain hidden information that help browsers interpret structure, meaning, style, interactions, etc.

Most of the visible information takes place in the body of the HTML document, while most of the hidden formation happens in the head of the HTML document.

Some information happens in external files, like CSS and JavaScript.

We link to these files in the head of the HTML document.

from web content to webpage

Page 4: Class 2: CSS Selectors, Classes & Ids

<html>

<head>

<title>Document Title</title>

</head>

<body>

...

</body>

</html>

basic html webpage

Page 5: Class 2: CSS Selectors, Classes & Ids

Css

Page 6: Class 2: CSS Selectors, Classes & Ids

CSS Stands for Cascading Style Sheet

Purpose

HTML tells us what to display CSS tells us how to display

Format

Simple text file Contains rules for displaying HTML

what’s css?

Page 7: Class 2: CSS Selectors, Classes & Ids

Inline Styles

defined within an individual tag with a lot of content starts to become inefficient

Internal styles

defined at the top of each individual page with a lot of pages, starts to become inefficient

External styles

defined once for your whole site all of your html pages link to the same file extremely efficient (and its what we’ll do in this class)

types of style sheets

Page 8: Class 2: CSS Selectors, Classes & Ids

Central definition of visual style make one change, the entire site is updated can be reused on any number of pages

Developers and designers can work independently

Same content can be restyled for lots of different media web print mobile phone iPod/iPhone/iPad

why external?

Page 9: Class 2: CSS Selectors, Classes & Ids

Cascading style rules are applied in order last definition takes precedence over the first

Order of priority 1 browser default lowest priority 2 external styles 3 internal styles 4 inline styles highest priority

characteristics

Page 10: Class 2: CSS Selectors, Classes & Ids

The only change in the HTML file is to add a line of code at the top:

<link rel=”stylesheet” type=”text/css” href=”styles.css” />

Tells browser to include a style sheet called styles.css

You can name the file anything you want (webstyles.css, printstyles.css, awesome.css)

Include the <link> tag just before the </head> tag in your HTML.

linking a css file to your html file

Page 11: Class 2: CSS Selectors, Classes & Ids

<html>

<head>

<title>Document Title</title>

<link rel=”stylesheet” type=”text/css” href=”styles.css” />

</head>

<body>

...

</body>

</html>

basic html webpage w/ link to css file

Page 12: Class 2: CSS Selectors, Classes & Ids

1 Create a text file and save it as styles.css

2 Add this line to your HTML, right before the </head> tag:

<link rel=”stylesheet” type=”text/css” href=”styles.css” />

3 Start writing CSS rules in your styles.css file

linking your first file demo

Page 13: Class 2: CSS Selectors, Classes & Ids

syntax

Page 14: Class 2: CSS Selectors, Classes & Ids

There are many style properties, don’t worry about memorizing them!

Keep a reference open while coding (www.w3schools.com)

be prepared...

Page 15: Class 2: CSS Selectors, Classes & Ids

selector = what you are defining

curly brackets { } = begin & end of rules for selector

property = set of display properties you can change

value = what you are changing the property to

semicolon ; = ends each rule

css syntax: vocabulary

Page 16: Class 2: CSS Selectors, Classes & Ids

selector { property: value; property: value; }

css syntax

Page 17: Class 2: CSS Selectors, Classes & Ids

selector { property: value; property: value; }

css syntax

selectoR is the html element these rules will change

Page 18: Class 2: CSS Selectors, Classes & Ids

selector { property: value; property: value; }

css syntax

PRoPeRt y is a display characteristic you are writing a rule for. Each selector can have multiple properties, and some selectors have very specif ic properties.

Page 19: Class 2: CSS Selectors, Classes & Ids

selector { property: value; property: value; }

css syntax

VAlue is the display characteristic that you want to apply to the property

Page 20: Class 2: CSS Selectors, Classes & Ids

sandwich { cheese: cheddar; bread: rye; condiment: mustard; condiment-style: spicy-brown; }

css syntax

Page 21: Class 2: CSS Selectors, Classes & Ids

h1 { font-family: Helvetica; font-size: 36px; font-weight:bold; text-transform:uppercase; color:#000000; }

css syntax

Page 22: Class 2: CSS Selectors, Classes & Ids

Classes & ids

Page 23: Class 2: CSS Selectors, Classes & Ids

These 2 attributes give you more control over the elements while using CSS

No inherent styles or properties

Different elements can share the same class

IDs are unique, and different elements can’t share them

html class & id attributes

Page 24: Class 2: CSS Selectors, Classes & Ids

<a href="http://google.com" class="button">Link</a>

<a href="http://google.com" id="button1">Link</a>

html class & id attributes

Page 25: Class 2: CSS Selectors, Classes & Ids

.button { font-size: 12px; color: #ff0000; text-decoration: none; }

#button1 { font-size: 12px; color: #ff0000; text-decoration: none; background-color: #ffff00; }

css class & id selectors

Page 26: Class 2: CSS Selectors, Classes & Ids

<a href="http://google.com" class="button">Link</a>

<a href="http://google.com" class=”button” id="button1">Link</a>

html class & id attributes

Page 27: Class 2: CSS Selectors, Classes & Ids

.button { font-size: 12px; color: #ff0000; text-decoration: none; }

#button1 { font-size: 12px; color: #ff0000; text-decoration: none; background-color: #ffff00; }

css class & id selectors

Page 28: Class 2: CSS Selectors, Classes & Ids

.button { font-size: 12px; color: #ff0000; text-decoration: none; }

#button1 { font-size: 12px; color: #ff0000; text-decoration: none; background-color: #ffff00; }

css class & id selectors

Page 29: Class 2: CSS Selectors, Classes & Ids

.button { font-size: 12px; color: #ff0000; text-decoration: none; }

#button1 { background-color: #ffff00; }

css class & id selectors

Page 30: Class 2: CSS Selectors, Classes & Ids

Color

Page 31: Class 2: CSS Selectors, Classes & Ids

rgb (red, green, blue) values 0 to 255 additive color black: 0,0,0 white: 255,255,255

hexadecimal or “hex" encoded value of rgb black: #000000 white: #FFFFFF

color values

Page 32: Class 2: CSS Selectors, Classes & Ids

rgb value

Page 33: Class 2: CSS Selectors, Classes & Ids

hexadecimal (hex) value

Page 34: Class 2: CSS Selectors, Classes & Ids

h1 { color: rgb(255,255,255); color: #ffffff; }

css property: color

Page 35: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; }

css property: background-color

Page 36: Class 2: CSS Selectors, Classes & Ids

typography

Page 37: Class 2: CSS Selectors, Classes & Ids

Browsers only display fonts installed on the user’s computer (with some recent exceptions)

To define fonts, the font-family: css property is used

Designers use font-stacking to create prioritized lists of fonts to display

(A safety net, incase the first desired typeface is unavailable)

Start with a very specific typeface, move to a generic classification

fonts

Page 38: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; font-family: Akkurat, Helvetica, sans-serif; }

css property: font-family

Page 39: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; font-family: Akkurat, Helvetica, sans-serif; font-size: 72px; }

css property: font-size

Page 40: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; font-family: Akkurat, Helvetica, sans-serif; font-size: 72px; font-weight: normal; }

css property: font-weight

Page 41: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; font-family: Akkurat, Helvetica, sans-serif; font-size: 72px; font-weight: normal; letter-spacing: 4px; }

css property: letter-spacing

Page 42: Class 2: CSS Selectors, Classes & Ids

h1 { color: #ffffff; background-color: #000000; font-family: Akkurat, Helvetica, sans-serif; font-size: 72px; font-weight: normal; letter-spacing: 4px; text-transform: uppercase; }

css property: text-transform