1 lecture 12 web publishing ii: cascading style sheets introduction to information technology with...

99
1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology h thanks to Mr. Mark Clulow Dr. Ken Tsang 曾曾曾 Email: [email protected] http://www.uic.edu.hk/~kentsang/IT/IT3.htm Room E408 R9

Upload: frank-bates

Post on 16-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

1

Lecture 12

Web Publishing II: Cascading Style Sheets

Introduction to Information Technology

With thanks to Mr. Mark Clulow

Dr. Ken Tsang 曾镜涛Email: [email protected]://www.uic.edu.hk/~kentsang/IT/IT3.htmRoom E408 R9

Page 2: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

2

Cascading What? So far, you have studied HTML and how

we can use it to present content on-line You may have also already used

Cascading Style Sheet (CSS) techniques without knowing it!

CSS saves Companies $billions world-wide!

CSS makes managing large web sites easy!

Page 3: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

3

What Is CSS? CSS is used in three different ways:

1. In-line Style2. Embedded Style3. External Style Sheet

Page 4: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

4

The Basics – HTML We start with our basic HTML file:

<html> <head>

<title>This is our page!</title> </head> <body>

<h1>Welcome!</h1> <p>Here is our page content … </p> <p><a href=“http://www.google.com.cn”>This is a link

to Google</a></p> </body> </html>

Page 5: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

5

How Does This Look?

Page 6: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

6

Decoding The HTML A quick reminder: html = Hyper-Text Mark-up Language hx – Heading # -

Heading 1 <h1> is the biggest Heading 6 is the smallest <h6>

p = paragraph a = anchor - a ‘link’ or a ‘bookmark’ http://www.W3Schools.com WILL help!

Page 7: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

7

Looking At The HTML

Page 8: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

8

The <html> Tag

Page 9: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

9

The <head> Tag

Page 10: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

10

The <title> Tag

Page 11: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

11

The <body> Tag

Page 12: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

12

The <h1> Tag

Page 13: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

13

The First <p> Tag

Page 14: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

14

The Second <p> Tag

Page 15: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

15

The <a> Tag

Page 16: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

16

So What Do We Know? We have a basic page, containing:

A header – a BIG header! <h1> Two paragraphs <p> A link to Google China <a> A page title <title> - found INSIDE the <head> tag

Page 17: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

17

1. In-line Styles In-line styles are quite literally that Here’s an example:

<h1 style="color:red;">Welcome!</h1>

If we include this in our HTML file, what happens?

Page 18: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

18

Explaining The Code The first part of the CSS is called the

‘property’, because it is a characteristic of the HTML element it refers to:

color : red ;

The second part is called the ‘attribute’ or ‘value’

Page 19: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

19

Using In-Line CSS

Page 20: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

20

Great! You’re probably thinking that you’re

ready to go now, but think about this:

What if you had ANOTHER <h1> tag in your page?

Here’s how it would look…

Page 21: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

21

Adding Another <h1> Tag

Page 22: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

22

Why Does This Matter? In the beginning, it’s good to keep many

of your colours the same

When you become more advanced, you will know how-best to use different colours effectively

Having separate styles for EVERY header makes future changes difficult!

Page 23: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

23

2. Embedded Styles Embedded means: ‘to incorporate or contain as an essential

part or characteristic ’

Our embedded style appears in the <head> tag

The style appears inside its own <style></style> tags

Page 24: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

24

Embedded Style Example<html>

<head><title>This is our page!</title><style type="text/css"><!-- h1 {

color: red;}--></style>

</head> <body>

<h1>Welcome!</h1> …

Page 25: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

25

The New Code Here we are introduced to some new code: <style type=“text/css”> - ‘declaration’ <!-- - used to hide CSS from anything that doesn’t

understand it h1 – You know this one! { - used to ‘encapsulate’ our styling color:red; - same as the in-line style } – close our styling for tag <h1> --> - finish hiding code </style> - close the embedded style instructions

Page 26: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

26

A Few Words About Colours In English, colour is spelt with a ‘u’, but in

American English it is not – ‘color’(Spelt is sometimes spelt ‘spelled’, but you’ll need to ask your English teacher for help with that!)

In HTML & CSS, ‘color’ is spelt the American way.

In HTML & CSS, centre is spelt the American way also – ‘center’.

This can get confusing sometimes!

Page 27: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

27

Finally On Colour… Computers are different to each

other. Some are old, some are new. Some

have big screens (or ‘monitors’) some have small ones

Some are Apple Mac, some are PCs, some are Mobile Phones or PDAs!

This becomes a BIG consideration in web design!

Page 28: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

28

Hex Colours If you state a colour by name, such as

‘red’, an old computer might show a completely different colour to the one you can see on your screen.

There is a set of codes created to make sure that the user sees the closest colour to the one YOU chose!

There are many colours to choose from!

Page 29: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

29

Hex Colours

Page 30: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

30

What Does This Mean? The Hex codes tell us a 6-digit number

we should use to describe a colour. For example, ‘red’ is ‘#FF0000’ We should change our CSS… h1 {

color: #FF0000;}

Advanced HTML editors make picking the Hex Codes easy!

Page 31: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

31

Advanced HTML Editors

Page 32: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

32

Back To The Code! So now that we have our Embedded

Style, we can delete the in-line style from our h1 tag:

<h1 style="color:red;“>Welcome!</h1>

…goes back to:

<h1>Welcome!</h1>

Page 33: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

33

Hooray! Our Headers Match!

Page 34: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

34

More Styles At A Glance Dreamweaver (an advanced HTML editor)

has a quick way to manage the basic CSS of a page

Pressing ‘ctrl + J’ opens the ‘Page Properties’ window

We can use this to quickly write the basic styles we want

We now have a short video for you to watch

Page 35: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

35

Dreamweaver Page Properties Video

Page 36: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

36

Growing Our Web Site This is all great for a single

page, but what happens when we add another page to our web site?

Now we will create a new page – contact.html – and link to it from our first page.

Page 37: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

37

Oh No! No Style!

Page 38: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

38

Can Anybody Tell Us Why?

Page 39: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

39

Embed Again? We could simply copy the code from the

top of the first page into our contact page. If we then want to change our headers to

green, or our background colour to blue, we have to update each page.

Whilst our site is only little, some web sites have over 1,000 pages!

Ahhhhhhhhhhhh!

Page 40: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

40

3. External Style Sheet It is good to use an external style sheet

EVERY TIME you develop web pages

It completely separates CONTENT from STYLE

We need to create a new file – we’ll call it style.css

We need a new line in our HTML too!

Page 41: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

41

Copying the Code into style.css

We can use any web editor or text editor (even notepad!) to create a CSS file.

We just copy it from our first page!

This is how style.css looks…

Page 42: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

42

File: style.css

Page 43: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

43

Link To The Style Sheet Now we have copied the style from our

first page, we can delete it from the <head> tag

We then need to add a new line:

<link type="text/css" href="style.css" rel="stylesheet" />

…to BOTH files (our first page and our contact page)

Page 44: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

44

Linking Our Pages Together To allow us to view both pages easily, we

will add a link to each one:

<a href=“index.html”>Home</a>

<a href=“contact.html”>Contact Us</a>

We can put these on both pages

Another Video shows us how…

Page 45: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

45

New Main Menu Video

Page 46: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

46

Now for the Magic! We will now change some information in

our 1 single style sheet and see what affect it has…

Let’s add the following to the <a> tag:

border-width: 1px;border-style: solid;border-color: #333333;padding: 4px;background: #EAEAEA;

Page 47: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

47

With The New Style Applied:

Page 48: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

48

And For My Next Trick…! Would you like to see the SAME HTML file,

but with a completely different CSS file?

Remember, the CONTENT or the INFORMATION is the SAME

…but the STYLE or DESIGN is different

Page 49: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

49

Same HTML – Different CSS!

Page 50: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

50

Same HTML – Different CSS!

Page 51: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

51

Some of the most common styles Here is a list of the most common styles found

in day-to-day web publishing: background-color: #EAEAEA;

font-size: x-small;color: #333333;font-weight: bold;border-color: #333333;border-style: solid;border-width: 2px;

Remember the ; at the end of every line!

Page 52: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

52

Find out more on-line! A quick web-search for some of these

terms will help you to find out more as and when you need help: CSS Reference W3Schools CSS CSS Guide CSS beginner CSS Examples

Page 53: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

53

‘class’ and ‘id’ Identifiers CSS supports what are called ‘identifiers’ It is an easy-to-use and flexible way to let the

CSS identify different parts of the code.

There are 2 types of identifiers – ‘class’ and ‘id’.

Think of these like our class here today – the ‘class’ is everyone in this room, your Student ID is unique to you

If we want to apply a style to a large number of HTML elements, we can use the ‘class’ identifier

If it is a style that is unique to one element, we should use the ‘id’ identifier

Page 54: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

54

Using ‘class’ and ‘id’ To apply a ‘class’ identifier on an HTML

element, we simply need to write ‘class=classname’

Replace classname with a sensible name that makes sense to you. This will help if ever you revisit this part of your code

<h1 class="main_header">Welcome!</h1> We then need to reference this new style

(list it) in our CSS file (file style.css)

Page 55: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

55

Using ‘class’ and ‘id’ It makes sense to place this next to the other ‘h1’

styles, but you can put it anywhere! h1 {

color:#FF0000;}h1.main_header {

color:#000000;background:#FFFF00;font-weight:bold;

}h2 { … …

Page 56: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

56

Using ‘class’ and ‘id’ To apply an ‘id’ identifier on an HTML

element, we simply need to write ‘id=idname’

Replace idname with a sensible name that makes sense to you. This will help if ever you revisit this part of your code

<p id="home_page_welcome">Here is our page content ...

We then need to reference this new style (list it) in our CSS file (file style.css)

Page 57: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

57

Using ‘class’ and ‘id’ We can place this code at the bottom of our

CSS file:

p#home_page_welcome {background : #EAEAEA ;color : #000000 ;width : 80% ;padding : 5px ;border : 1px solid #000000 ;text-align : right ;

}

Page 58: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

58

Using ‘class’ and ‘id’

Page 59: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

59

Using ‘class’ and ‘id’ Looking at our CSS, can anybody tell us

how the two are referenced?

id : p#home_page_welcome

class : h1.main_header

Look for the HTML reference, the id or class-name and one other difference!

Page 60: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

60

Using ‘class’ and ‘id’ If you use ‘class=’ in your HTML, it is referred

to in the CSS with a full-stop . If you use ‘id=’ in your HTML, it is referred to

in the CSS with the hash sign #

Let’s do some quick examples – shout out either ‘ID’ or ‘CLASS’

If we want to apply a style to more than one HTML element, we can even leave out the HTML – see if you can spot them!

Page 61: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

61

ID or CLASS?

p.this_content

Page 62: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

62

ID or CLASS?

p.this_content

CLASS!

Page 63: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

63

ID or CLASS?

a#styled

Page 64: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

64

ID or CLASS?

a#styled

ID!

Page 65: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

65

ID or CLASS?

p#class

Page 66: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

66

ID or CLASS?

p#class

ID!

Page 67: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

67

ID or CLASS?

h1.big_heading

Page 68: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

68

ID or CLASS?

h1.big_heading

CLASS!

Page 69: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

69

ID or CLASS?

.many_elements

Page 70: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

70

ID or CLASS?

.many_elements

CLASS!

Page 71: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

71

ID or CLASS?

h3#info

Page 72: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

72

ID or CLASS?

h3#info

ID!

Page 73: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

73

The Basics covered… So we have now looked at the basics,

but what else can we use CSS for?

1. Applying images to our pages2. Changing the layout of our

pages

This is where it gets REALLY exciting!

Page 74: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

74

Using <div> and <span> So far we have used the ‘hx’ tags for

headers, the ‘p’ tag for paragraphs and the ‘a’ tag for anchor links.

‘div’ and ‘span’ are tags that can be VERY useful!

They allow us to add extra style elements to our page, but keep our content clean and tidy

Page 75: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

75

‘div’ versus ‘span’ ‘div’ acts like a paragraph ‘p’ tag in that it

creates a break – a new line ‘span’ – with no styling applied to it – does not

affect the formatting of the code at all ‘div’ is used to create sub-sections within our

content ‘span’ is used to apply styles to tiny elements

of our page

Usage: div – 90% vs. span - 10%

Page 76: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

76

Adding <div> and <span>

Page 77: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

77

Adding <div> and <span>

Page 78: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

78

Adding <div> and <span>

Page 79: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

79

Adding <div> and <span>

Page 80: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

80

Adding <div> and <span>

Page 81: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

81

Changes To The HTML Output

Page 82: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

82

Changes To The HTML Output

Page 83: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

83

Why Was There No Change?

Can anybody tell us why there was no change to the HTML file output… yet?

Here’s a clue… look in the CSS file!

Page 84: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

84

Why Was There No Change? There was no change to the HTML file, because

we haven’t added any CSS to our new elements ‘div’ and ‘span’

We can add CSS code for ALL the ‘div’ elements on our page, or use the class identifiers to add style to each one in turn

We can add CSS code for ALL the ‘span’ elements on our page, or use the id identifier to add style to our one unique link to Google.

OR we can do ALL of these things!

Page 85: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

85

CSS For The <a> Tag This is the CSS we added to the anchor

‘a’ tag: line-height : 24px ;

padding-left : 28px ;

background-image : url(images/link_arrow.png) ;

background-position : left ;

background-repeat : no-repeat ;

Page 86: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

86

CSS For The <a> Tag

Page 87: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

87

‘background-repeat’ Options

Page 88: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

88

Mouse-Over Background Change

When we used Dreamweaver to create our initial Page Properties styles, it created a few different styles for ‘a’ links

This refers to the ‘state’ of the link, or an ‘event’ happening

The states are Link, Visited, Active and Hover

Page 89: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

89

Mouse-Over Background Change

‘link’ – applies to all unvisited links

‘active’ – a link becomes ‘active’ when you click it

‘visited’ – if a link has already been clicked

‘hover’ – when the mouse is over the link

Page 90: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

90

Mouse-Over Background Change The ‘link property’ is applied using a :

directly after the a. Here is our new CSS: a:hover {

text-decoration : underline ;

color : #003399 ; /* THIS CODE CHANGES THE GREEN ARROW TO A BLUE ONE! */

background-image : url(images/link_arrow_over.png) ;

}

Page 91: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

91

Mouse-Over Background Change Did you notice the arrow change to blue

when the mouse was moved over it?

Page 92: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

92

Heading Background Image By using the ‘background-image’ and

‘background-repeat’ properties, we can add a faded image to the background of the <h1> tag.

This is the image we will repeat: This is the CSS we will use:

padding : 5px ;background-image : url(images/header_1_fade.gif) ;background-repeat : repeat-x ;

Page 93: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

93

Heading Background Image

Page 94: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

94

Paragraph Background Image From this page view we can also see what

affect this CSS has on our page: p#home_page_welcome {

/* THIS STYLE WAS ALREADY HERE */

background: #EAEAEA;color:#000000;width:80%;padding:5px;border:1px solid #000000;text-align:right;/* LET'S ADD THE FADED BACKGROUND! */background-image : url(images/special_p_fade_top.gif) ;background-position : top ;background-repeat : repeat-x ;

}

Page 95: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

95

Paragraph Background Image

Page 96: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

96

Summary In this session we learnt:1. CSS stands for ‘Cascading Style Sheet’2. It lets us separate CONTENT from STYLE3. We could also say it lets us separate

INFORMATION from DESIGN4. There are many ways we can use CSS

to make our web sites look great!

Page 97: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

97

Summary5. We can apply style to any HTML tag

INSIDE the <body> tag6. There are 3 types:

1. In-line Styles2. Embedded Styles3. External Style Sheet

7. In-line stlye happens with each element we wish to affect

8. Embedded Style appears in the <head> tag

Page 98: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

98

Summary9. External style is held in a separate CSS

file that we link to from within the <head> tag

10. External Style sheets make site-wide changes quick and easy

11. We can apply style to any HTML element12. We can use the class and id identifiers

to style groups page items or individual items

Page 99: 1 Lecture 12 Web Publishing II: Cascading Style Sheets Introduction to Information Technology With thanks to Mr. Mark Clulow Dr. Ken Tsang 曾镜涛 Email: kentsang@uic.edu.hk

99

Forum Questions Please log on to:

http://www.uic.edu.hk/bbs/

and answer the questions we have already posted on there!

There are some links you might find useful or interesting on there too!