a css file consists of rule sets. h1 { color: navy; } selector property value within the brackets...

18
C hapter4 How to use C SS to form atthe elem ents ofa w eb page

Upload: estella-adams

Post on 19-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Chapter 4

How to use CSS to format the elements

of a web page

Page 2: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

A CSS file consists of rule sets.

H1 {color: navy;}

selector

property

value

Within the brackets are one or more rules

/*This rule adjust the styles for the headings */

A simple CSS document with comments

Page 3: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Three ways to provide styles Use an external style sheet <link rel="stylesheet" href="styles/main.css">

Embed the styles in the head section <style> body { font-family: Arial, Helvetica, sans-serif; font-size: 87.5%; } h1 { font-size: 250%; } </style>

Use the style attribute to apply styles to a single element <h1 style="font-size: 500%; color: red;"> Valley Town Hall</h1>

Page 4: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

The sequence in which styles are applied Styles from an external style sheet

Embedded styles

Inline styles

Page 5: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

A head element that includes two style sheets <head> <title>San Joaquin Valley Town Hall</title> <link rel="stylesheet" href="../styles/main.css"> <link rel="stylesheet" href="../styles/speaker.css"> </head>

The sequence in which styles are applied From the first external style sheet to the last

Page 6: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

How to specify the medium for a style sheet <link rel="stylesheet" href="../styles/print.css" media="print">

Useful if you want a web page to specifically be formatted for printing as a document.

BBC News

Page 7: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles
Page 8: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Another way to provide the shiv <head> <script> document.createElement(article); document.createElement(aside); document.createElement(figure); document.createElement(footer); document.createElement(header); document.createElement(nav); document.createElement(section); </script> </head>

Page 9: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 9

CSS for using HTML5 tags in older browsers article, aside, figure, footer, header, nav, section { display: block; }

Page 10: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Common units of measure

Symbol Name Type Description

px pixel absolute A single dot on a monitor. The number of dots per inch depends on the resolution of the monitor.

pt point absolute A point is 1/72 of an inch.

em ems relative One em is equal to the font size for the current font.

% percent relative A percent specifies a value relative to the current value.

• To specify an absolute measurement, you can use pixels or points.

• To specify a relative measurement, you can use ems or percents.

Page 11: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 11

The HTML for a web page <body> <header> <h1>San Joaquin Valley Town Hall</h1> </header> <section> <p>Welcome to San Joaquin Valley Town Hall. We have some fascinating speakers for you this season!</p> </section> </body>

CSS that uses relative units of measure body { font-size: 87.5%; margin-left: 2em; } header { padding-bottom: .75em; border-bottom: 3px solid black; margin-bottom: 0; } h1 { font-size: 200%; margin-bottom: 0; }

Page 12: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 12

Three ways to specify colors With a color name color: silver;

With an RGB (red-green-blue) value color: rgb(100%, 40%, 20%); color: rgb(255, 102, 51);

With a hexadecimal number for an RGB value color: #ffffff; color: #000000; color: #ff0000;

Page 13: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 13

16 descriptive color names H1 { color: silver; }

black silver white aqua

red lime green maroon

yellow olive purple teal

gray blue fuchsia navy

Page 14: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 14

With an RGB (red-green-blue) value

H1 {color: rgb (100%, 40%, 20%); }

Page 15: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 15

CSS that uses hexadecimal values for colors body { font-size: 87.5%; margin-left: 2em; background-color: #FFFFCC; } h1 { font-size: 200%; color: #00F; }

http://www.w3.org/TR/css3-color

http://www.colorpicker.com/

Page 16: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 16

The HTML in a web browser

Accessibility guideline for the visually impaired Dark text on a light background is easier to read, and black type

on a white background is easiest to read.

Page 17: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 17

HTML that can be selected by type, id, or class <section id="main"> <h1>The 2011-2012 Speaker Lineup</h1> <p class="blue">October 19, 2011: Jeffrey Toobin</p> <p class="blue"> November 16, 2011: Andrew Ross Sorkin</p> </section> <footer> <p class="blue right">Copyright 2012</p> </footer>

The elements displayed in a browser

Page 18: A CSS file consists of rule sets. H1 { color: navy; } selector property value Within the brackets are one or more rules /*This rule adjust the styles

Slide 18

CSS rule sets that select by type, id, and class All elements

* { margin: .5em 1em; }

Elements by type

h1 { font-family: Arial, sans-serif; } p { margin-left: 3em; }

One element by ID

#main { border: 2px solid black; padding: 1em; }

Elements by class

.blue { color: blue; }

.right { text-align: right; }