CASCADING STYLE SHEETS

20
CASCADING STYLE SHEETS

description

CASCADING STYLE SHEETS. CSS Advantages. Lets you set up styles all in one place They can then be invoked just using the names. What CSS Can do. Change the look of your site easily since all styles are defined in one place - PowerPoint PPT Presentation

Transcript of CASCADING STYLE SHEETS

Page 1: CASCADING    STYLE     SHEETS

CASCADING STYLE SHEETS

Page 2: CASCADING    STYLE     SHEETS

CSS Advantages

Lets you set up styles all in one place

They can then be invoked just using the names

Page 3: CASCADING    STYLE     SHEETS

What CSS Can do

Change the look of your site easily since all styles are defined in one place

Use font sizes outside HTML’s limitation of seven

reformat HTML tags– for instance, make the bold tag red with a special font

Customize your link styles - get rid of the underline.

Page 4: CASCADING    STYLE     SHEETS

Advantages of CSSYou only have to enter your style components once

Your site will load faster than if you coded everything separately because your CSS document will be cached on the user’s computer

Allows users to override settings to make the site easier for them to use.

Page 5: CASCADING    STYLE     SHEETS

Disadvantage of CSS

work only on version 4 or later browsers

The good news: more than 95% of all browsers render the basics.

Page 6: CASCADING    STYLE     SHEETS

CSS Involve

Styles : a definition of fonts, colors, etc.

Selectors: your unique names for your styles

Page 7: CASCADING    STYLE     SHEETS

Basic Types of Selectors

Class : defines styles that can be used without redefining plain HTML tags

Type : defines styles that modify the appearance of HTML tags

ID : define styles for a single tag.

Page 8: CASCADING    STYLE     SHEETS

Class and ID attributesThe same class can be applied to multiple tags:

<B class='1'>

<P class='1'>

BUT

An ID selector should be unique for each tag:

<B id='1'>

<B id='2'>

....

Page 9: CASCADING    STYLE     SHEETS

Syntax for Class Selectors

.Selector {Property:Value;Property2:Value…}

.NewBold {Font-Family:Arial;Color:red}

applies to all the following

<B class='NewBold' id='Name'>John</B>

<B class='NewBold' id='LName'>Smith</B>

<P class='NewBold' id='About'>...</P>

Page 10: CASCADING    STYLE     SHEETS

Syntax for Type Selectors

TAGNAME {Property:Value;Property2:Value…}

B {Font-Family:Arial;Color:red} affects only the B tags

<B class='NewBold' id='Name'>John</B><B class='NewBold' id='LName'>Smith</B><P class='NewBold' id='About'>...</P>

Page 11: CASCADING    STYLE     SHEETS

Syntax for ID Selectors

#Selector {Property:Value;Property2:Value…}

#Name {Font-Family:Arial; Color:red}

changes only the first tag:

<B class='NewBold' id='Name'>John</B>

<B class='NewBold' id='LName'>Smith</B>

<P class='NewBold' id='About'>...</P>

Page 12: CASCADING    STYLE     SHEETS

An Example<HTML>

<HEAD> what follows defines a class called headline <style type="text/css">

.headline {color:red; font-size:22px; font-family:arial} </style>

</HEAD>

<BODY><b>This is normal bold</b><br><b class="headline">This is headline style bold</b> invokes the style defined above as headline

</BODY>

</HTML>

Page 13: CASCADING    STYLE     SHEETS

What about conflicts?

.NewBold {Color:red}

B {Color:blue}

#Name {Color:green}

<B class='NewBold' id='Name'>...</B>

where styles overlap, the most specific prevails:ID -> Class -> Type

Page 14: CASCADING    STYLE     SHEETS

Tags that Invoke Styles

<SPAN></SPAN>

no line breaks before or after

<DIV></DIV> inserts a line break before and after

(like <P> or <TABLE>)

Page 15: CASCADING    STYLE     SHEETS

Grouping Selectors

Without grouping:

.headlines{font-family:arial; color:black; background:yellow; font-size:14pt;}

.sublines {font-family:arial; color:black; background:yellow; font-size:12pt;}

Page 16: CASCADING    STYLE     SHEETS

With Grouping

.headlines, .sublines, .infotext

{font-family:arial; color:black; background:yellow;}

.headlines {font-size:14pt;}

.sublines {font-size:12pt;}

.infotext {font-size: 10pt;}

Page 17: CASCADING    STYLE     SHEETS

This applies Styles to one page

<HTML>

<HEAD> what follows defines a class called headline <style type="text/css">

.headline {color:red; font-size:22px; font-family:arial} </style>

</HEAD>

<BODY><b>This is normal bold</b>

<b class="headline">This is headline style bold</b> invokes the style defined above as headline

</BODY>

</HTML>

Page 18: CASCADING    STYLE     SHEETS

But you can define styles to apply to your entire site…

By writing all CSS definitions to a text file that is loaded with the first page that a visitor sees at your site.

Page 19: CASCADING    STYLE     SHEETS

Call your text file something.css For instance: news.css

Where you’ve coded:

.headlines, .sublines, infotext {font-face:arial; color:black; background:yellow; font-weight:bold;}

.headlines {font-size:14pt;}.sublines {font-size:12pt;}

Page 20: CASCADING    STYLE     SHEETS

Then go get it

Code in the HEAD SECTION of each page:

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