Top Banner
Cascading Style Sheets (CSS)
17

Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

Jan 17, 2016

Download

Documents

Phoebe Anderson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

Cascading Style Sheets(CSS)

Page 2: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such as HTML

Page 3: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

To separate structure and content from appearance

Create consistent appearance

Ease of maintenance

Increase accessibility

Apply additional effects

Reduce web page file size

Page 4: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

Create one style sheet for whole website

Use link tag to use for several web pages

Make changes in one file

Page 5: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

User can override your style sheet

You can create different style sheets for alternative devices

Page 6: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

Add hover effect to links

Remove underlines on links

Add horizontal rule to headings

Use instead of a table for a border

Control paragraph, line, letter spacing

Use instead of tables for layout

Page 7: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

In-line - add to HTML tag – As we have been doing<H1 style="color: maroon">

Embedded style sheets – Use style tags in the head of document<style> </style>

External style sheets – Link to external file<link href="style.css">

Page 8: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

<H1 style="color: maroon">

Similar to adding attributes to html tags

Disadvantages- decreased accessibility- increased file size- harder to update

Page 9: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

<style>

h1 {font-family: arial, sans-serif;}

</style>

- Put rules between style tags

- Put in head section

- Add html comment tags

- Use when single document has unique style

Page 10: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

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

Save rules in external file

Advantages- ease of maintenance- use less disk space - increase accessibility

Page 11: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

name_of_tag { property: value(s) ; …}H1 { font-family: Times, serif; }

---------------------------------------------------------------------

Multiple properties on one rule:H1 {color: black; font-weight: bold;}

Group tags:H1, H2, H3 { font-family: Times, serif; }

Page 12: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

To create rules that can be applied to a variety of html tags

<style>.bar {color: maroon; font-size: smaller; background-color: yellow;}</style>

<p class="bar">text</p>

<p><a href="url.htm" class="bar">link</a> </p>

Page 13: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

- Add hover effect to links

- Remove underlines on links

- Add horizontal rule to headings

- Control paragraph, line, letter spacing - Use instead of a table for a border

- Use instead of tables for layout

Page 14: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

a:link{ .... }

a:visited{ ....}

a:hover{ ....}

a:active{ ....}

a.thislink:link{ .... }

a. thislink:visited{ ....}

a.thislink:hover{ ....}

a.thislink:active{ ....}

<a href=“xxx.htm”>Click me</a>

<a href=“xxx.htm” class=“thislink”>Click me</a>

Page 15: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

Division Tags

<div> ……<div>

Give each div tag an id:

<div id=“div_id”> ……</div>

Referenced in CSS with #:

#div_id{….}

Page 16: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

“position:relative”

Position supplied by the margin tag...

#div_id{ float:left;

position:relative;margin: 0px 0px 0px 0px;

}

TOP, RIGHT, BOTTOM, LEFT

CLEAR FLOATS (Line break) See example

Page 17: Cascading Style Sheets (CSS). A style sheet is a document which describes the presentation semantics of a document written in a mark-up language such.

“position:absolute”

Position supplied top & left attributes...

#div_id{ position:absolute;

top: 10px;left: 20px;

}

See example provided

Will become useful in our Lunar Lander Game