Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Cascading Style Sheets (CSS)

Similar presentations


Presentation on theme: "Introduction to Cascading Style Sheets (CSS)"— Presentation transcript:

1 Introduction to Cascading Style Sheets (CSS)

2 What are Cascading Style Sheets?
Cascading Style Sheets allow for the separation of a web page’s structure and content. CSS, or Cascading Styles Sheets, is a way to style HTML. Whereas the HTML is the content, the style sheet is the presentation of that document. CSS removes the visual instructions out of HTML and places them in a separate cacheable document.

3 What Are Cascading Style Sheets (Continued)
Setting colours and backgrounds, fonts, and white space are among the most common tasks of CSS. CSS is a specification under W3C. (

4 WWW - CSS History The world wide web (WWW) was created in 1990 by Tim Berners-Lee CSS was introduced in 1996 by Hakon Wium Lie & Bert Bos.

5 The Beauty in CSS Design
Visit the following URL to see an example of CSS in action:

6 Internal CSS You can include a CSS inside a web page document using the following syntax: <head> <style type = “text/css”> h1, h2, p, li {font-style: italic } </style> </head>

7 External CSS A CSS can also be referenced outside of the web document.
<head> <link href="my_style_sheet.css" rel="stylesheet"> <title>Introduction to Cascading Style Sheets</title> </head>

8 Inline Style Example: Not quite recommended
<p style="color: #ff0000;">Some red text</p> Not quite recommended

9 CSS syntax A CSS syntax consists of two parts: 1. Selector – (The part before the left curly brace). 2. Declaration – (The part within the curly braces).

10 CSS syntax (Continued)
A declaration has two (2) parts separated by a colon Property: The part before the colon 2. Value: The part after the colon

11 Units em (such as font-size: 2em) is the unit for the calculated size of a font. So "2em", for example, is two times the current font size. px (such as font-size: 12px) is the unit for pixels. pt (such as font-size: 12pt) is the unit for points. % (such as font-size: 80%) is the unit for percentages.

12 Colours color: red; color: rgb(255, 0, 0); color: rbg(100%, 0%, 0%);
color: #FF0000; color: #F00;

13 Text font-family : “Times New Roman”; Arial ; font-size : 0.8em; 2em; font-weight : bold; normal; font-style : italic; normal; text-decoration : overline; line-through; underline; none; text-transform : capitalize; uppercase; lowercase; none;

14 Text Spacing letter-spacing: 0.5em; word-spacing: 2em;
line-height: 1.5; text-align: left; right; center; justified;

15 The Box model margin border padding content

16 Margins and Padding h2 { font-size: 1.5em; background-color: #ccc;
margin: 1em; padding: 3em; } h3 { margin: 0 1px 2px 3px ; } (margin-right, margin-left, margin-top, margin-bottom)

17 Margins : 4 Values h3 { margin: 0 1px 2px 3px ; }
(margin-right, margin-left, margin-top, margin-bottom)

18 Borders h2 { border-style: dashed; border-width: 3px;
border-left-width: 10px; border-right-width: 10px; border-color: red; }

19 Comma Separated List h1 {font-style: italic} h2 {font-style: italic} h3 {font-style: italic} Because all declarations are the same, the rules can be grouped into a comma – Separated list. h1, h2, h3 {font-style: italic }

20 Semicolon Separated List
A selector may have more than one declaration: h1 {color: green } h1 {text-align: center } Declarations relating to the same selector can be grouped into a semicolon separated list: h1 { color: green; text-align: center; }

21 CSS URL Link Examples a: link { text-decoration: underline } a: visited { text-decoration: none } a: link, a: visited {text-decoration: none } a: hover {background: black }

22 CSS Division Divisions are a block level HTML element used to define sections of an HTML file. A division can contain all the parts that make up your website. <div id="container"> Site contents go here </div>

23 CSS Span Spans are very similar to divisions except they are an inline element versus a block level element. No linebreak is created when a span is declared. <span class="italic">This text is italic</span> .italic{ font-style: italic; }

24 CSS Classes The class selector allows you to style items within the same HTML element differently. p.first { color: blue; } p.second { color: red; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html> <head> <title>CSS Example</title> <link rel="stylesheet" type="text/css" href="web.css" /> <p>This is a normal paragraph</p> <p class=“first”>This is the first paragraph</p> <p class=“second”>This is the second paragraph</p>

25 CSS ID IDs are similar to classes, except once a specific id has been declared it cannot be used again within the same HTML file. <div id="container"> Everything within my document is inside this division. </div> #container{ width: 80%; margin: auto; padding: 20px; border: 1px solid #666; background: #ffffff; }

26 Hands-on

27 Create NEW HTML

28 Create a new CSS

29 Internal CSS 1) Type in any class name

30 External CSS 1) Type in any class name

31 Save CSS file

32 Edit a CSS Class

33 Attach an existing CSS file

34 Apply CSS Class to HTML 1. Highlight the text 2. Select the class

35 Preview the HTML Press F12 Save the HTML file.

36 Exercise

37 Your turn Open a browser and navigate to A modified copy of the above web site has been uploaded to By using Dreamweaver or whatever tool, edit the appropriate file(s) of (2) above, so that it looks like the same as the original one.

38 CSS Tutorial Sites Visit the following URL for a tutorial on using CSS:

39 Reference Cascading Style Sheets – Designing For The Web – Third Edition – Hakon Wium Lie & Bert Bos


Download ppt "Introduction to Cascading Style Sheets (CSS)"

Similar presentations


Ads by Google