stylin’ with css monday october 8 th and tuesday october 9 th

21
Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

Upload: brenda-french

Post on 02-Jan-2016

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

Stylin’ with CSS

Monday October 8th and

Tuesday October 9th

Page 2: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

2

Topics

What is CSS Why CSS CSS Examples

Page 3: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

3

What is CSS?

Stands for Cascading Style Sheets Used to change the “presentation” of a Web

page Used in conjunction with HTML in several

ways Inline -- embedded within the HTML element Internal -- placed within the header information External -- coded in a separate document

Allows style control of multiple pages all at once

Page 4: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

4

HTML vs. CSS

HTML intended to show what the text is being used for Defines it’s semantic meaning Designed to say things like “This is a paragraph”

not “This is a paragraph that is centered with a font color of blue”

CSS used for presentation only Defines how the HTML should be displayed

Page 5: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

5

Inline Style Should only be used sparingly Applies to a single tag Used as a “quick fix” For example:

<h1>This is an h1 without style</h1>

<h1 style=“font-family: verdana; text-align: center“>This is an h1 with style</h1>

Page 6: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

6

Inline Style Example

Page 7: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

7

Internal Style

Placed in the header of the page between the <head>…</head> tags.

Contains styles that are used throughout the whole page rather than on a single tag.

Enclose each “rule” in the <style>…</style> tag.

Page 8: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

8

Internal Style Example

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/transitional.dtd”>

<html>

<head>

<title>CMSC104 HTML Template</title>

<style type=“text/css”>

h1{

font-family: verdana;

text-align: center;

}

</style>

</head>

<body>

Page 9: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

9

A Closer Look at the Style

<style type=“text/css”>

h1{

font-family: verdana;

text-align: center;

}

</style>

selector

property

value

rule

How many attributes does the style tag have in this example?

Page 10: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

10

Changing the Font Face

Use the font-family property Will only display fonts already installed on the

end user’s computer If the font is not installed, displays the

browser’s default font, usually Times New Roman.

Can give more than one value in the CSS, just in case

To see a list of Web fonts:http://www.angelfire.com/al4/rcollins/style/fonts.html

Page 11: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

11

Font Example

<html>

<head>

<title>CMSC104 HTML Template</title>

<style type=“text/css”>

body{

font-family: verdana, helvetica, arial, sans-serif;

}

</style>

</head>

<body>

Do you like this font?

</body>

</html>

Page 12: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

12

Font Example Screenshot

Page 13: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

13

Working with Color

background-color -- changes the background color color -- changes the text color Can be applied to most selectors. ie: body, p, etc...

black lime maroon purple

white olive navy teal

silver green red fuchsia

gray yellow blue aqua

orange

Chart of possible CSS color values

Page 14: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

14

Color Example

<html>

<head>

<title>CMSC104 HTML Template</title>

<style type=“text/css”>

body{

background-color: black;

color: orange;

}

</style>

</head>

<body>

Happy Halloween!!

</body>

</html>

Page 15: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

15

Color Example Screenshot

Page 16: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

16

Changing the Font Size

Sample Usage Possible values

font-size: 14pt; Can use number and unit (as in 12pt) or keywords: xx-small, x-small, small, medium, large, x-large,xx-large. (There are other possibilities but we won’t be discussing them now.)

Page 17: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

17

Aligning text

Sample Usage Possible values

text-align: center; left, right, center, justify

Page 18: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

18

CSS for Emphasis

Sample Usage Possible values

font-style: italic; normal, italic, oblique

font-weight: bold; normal, bold, bolder, lighter

Page 19: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

19

CSS Comments

You can place a comment in CSS by using the following syntax:

<style type=“text/css”> /* body layout */ body{ background-color: black; color: orange; } </style>

Page 20: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

20

Example with Multiple Rules

<html>

<head>

<title>CMSC104 CSS Example</title>

<style type=“text/css”>

body{

color: purple;

}

h1{

color: red;

}

</style>

</head>

<body>

<h1>What color is this Heading?</h1>

What color am I?

</body>

</html>

Page 21: Stylin’ with CSS Monday October 8 th and Tuesday October 9 th

21

Multiple Rule Screenshot