Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell.

Similar presentations


Presentation on theme: "Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell."— Presentation transcript:

1 Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell

2 What is CSS? A set of rules for displaying markup content

3 What is CSS? A set of rules for displaying markup content Cascading: Display rules “cascade” down The most specific rule is used

4 What is CSS? A set of rules for displaying markup content Cascading: Display rules “cascade” down The most specific rule is used Styles Sheet: Rules are created as styles

5 The Need for CSS Fixing kludges in HTML

6 The Need for CSS Fixing kludges in HTML Separation of content and display

7 The Need for CSS Fixing kludges in HTML Separation of content and display More options for displaying content

8 The Need for CSS Fixing kludges in HTML Separation of content and display More options for displaying content Efficiency

9 CSS Example http://www.csszengarden.com/

10 Visual Display in HTML This will be a heading 1 in red Georgia font Every time I want my text to look the same, I have to retype or cut and paste all of this markup

11 Style Rules CSS style rules look like this: Selector { property0:value0; property1:value1; propertyZ:valueZ }

12 CSS Reference http://www.w3schools.com/css/css_reference.asp

13 Inline Style Sheet Using a Style Attribute This also shows up as heading 1 in red Georgia font. I don’t have to use the font tag any more. However, I still have to retype or cut and paste the markup every time I want to use the same style. Notice that we switch from the attribute “face” for the “font” element to the property “font-family” in CSS. Names of attributes in HTML do not necessarily exactly match the names of properties in style rules.

14 Inline Style Sheet Using a Style Attribute In-Class exercise: Create an inline stylesheet that makes all paragraph text black, centered, and 12 pixels in size.

15 Inline Style Sheet In-Class exercise: Create an inline stylesheet that makes all paragraph text black, centered, and 12 pixels in size. black, centered, 12px text This is black, 12px, centered text.

16 Embedded Style Sheet Using a Style Element Embedded style sheet h1 {color:red; font-family: Georgia, Times New Roman, Times, serif;} This will also appear as a heading 1 in red Georgia font. In the head of this document, I declared an embedded style sheet that will make all h1 tags in this document red with Georgia font But how do I make some h1 tags use this style and others look different?

17 Embedded Style Sheet Using a Style Element In-Class exercise: Create an embedded stylesheet that makes all paragraph text blue, background-color #777777, and 14 pixels in size.

18 Embedded Style Sheet Using a Style Element In-Class exercise: Create an embedded stylesheet that makes all paragraph text blue, background-color #777777, and 14 pixels in size. Embedded style sheet p {color:blue; background-color:#777777; font-size:14px;} This should be blue with gray background and size 14

19 Class Selectors Embedded style sheet.red {color:red; font-family: Georgia, Times New Roman, Times, serif;} This will also appear as a heading 1 in red Georgia font. In the inline style sheet I declared a generic class style that applies red Georgia to ANY element declared as class red. I simply change a value in the style element in the head and all elements using that style will change to match This will also be in red Georgia font. Now I can be very specific when I apply styles, but I still have to add the same markup in the HEAD to each of my pages. How do I make all my pages use the same styles without copying markup to each page?

20 Linked Style Sheets Linked style sheet This will also appear as a heading 1 in red Georgia font. In the head of this document I declared a link to an outside stylesheet named “mystyle.css”. In that external stylesheet I place all of the style declarations I was using in my inline stylesheet Now I can change the way all of my pages display simply by modifying a value in my single external stylesheet. How efficient!

21 Example External Stylesheet h1.redH1 { color:red; font-family: Georgia, Times New Roman, Times, serif } body { background-color: #333333; }.blueback { background-color: blue; color: white } p { font-size: 12px; text-align: center; }

22 Linked Style Sheet Using an External Stylesheet In-Class exercise: Create an external stylesheet that defines a new style named phunky that makes text pink, centered, and bold. The sheet should also make the background color of the page ”antiquewhite”

23 Linked Style Sheet Using an External Stylesheet In-Class exercise: Create an external stylesheet that defines a new style named phunky that makes text pink, centered, and bold. The sheet should also make the background color of the page ”antiquewhite”.phunky { color:pink; text-align: center; font-weight: bold; } body{ background-color: antiquewhite }

24 Cascading revisited When using multiple styles that conflict, which will be displayed?

25 Cascading revisited When using multiple styles that conflict, which will be displayed? Order: 1. Inline style sheet 2. Embedded style sheet 3. External style sheet 4. Browser default

26 Style Rule Values Colors: Names for some: blue, red, green, pink Hexadecimal #0000FF, #FF0000, #00FF00, #FF3399 RGB rgb(0,0,255), rgb(255,0,0), rgb(0,255,0) RGB% rgb(0%,0%,100%), rgb(100%,0%,0%)

27 Style Rule Values Font size: px for pixels (a dot on the screen) font-size: 12px pt for point (1/72 of an inch) font-size: 12pt pc for pica (12 points) font-size: 2pc

28 Modifying Hyperlinks We can modify the way hyperlinks appear by creating style rules modifying the tag with the following “pseudo- classes”: link visited hover active

29 Modifying Hyperlinks a:link {color:#0000ff} a:visited {color: #00ff00} a:hover {color:fuschia; font-weight:bold} a:active {font-size:30pt} Order here is important!

30 Modifying Hyperlinks You can also combine a class selector with a pseudo-class: a.outsidelink:link {color:#0000ff} a.insidelink:visited {color: #00ff00} a.fun:hover {color:fuschia; font-weight:bold}

31 Span and Div and are tags that let you select a group of elements and apply styles to them is an inline tag no breaks are added before or after is a block tag a break is usually added by the browser before and after the tags

32 Span and Div Span and Div.red {color:red; font-family: Georgia; font-weight:bold;} This will also appear as normal paragraph text except here because I made the text red,bold, and Georgia font without breaking up the paragraph. Now I am back to normal... I start off as normal paragraph text here as well. However, when I use a div tag to apply a style, my paragraph is broken like this. You can see that the browser sets off this text from the text before and after it. Now I am back to normal again.

33 Putting it all together In-class exercise: Create a web page with an external style sheet that does the following: All paragraph text is white with a blue background and centered. All links get bigger and change colors when hovered over Background color is “aliceblue” Creates a style “redstyle” that makes text 16px red Garamond. All h1 text is centered and underlined.


Download ppt "Cascading Style Sheets: Basics I450 Technology Seminar Copyright 2003, Matt Hottell."

Similar presentations


Ads by Google