creating css

42
Ms. Josephine T. Eduardo CSD, Faculty CREATING CSS

Upload: lorenz-pasensyoso

Post on 25-Dec-2015

12 views

Category:

Documents


0 download

DESCRIPTION

css

TRANSCRIPT

Page 1: Creating Css

Ms. Josephine T. EduardoCSD, Faculty

CREATING CSS

Page 2: Creating Css

• CSS stands for Cascading Style Sheets

• Styles define how to display HTML elements

• External Style Sheets can save a lot of work

• External Style Sheets are stored in CSS files

What is CSS?

Page 3: Creating Css

• Style sheets are files or forms that describe the layout and appearance of a document.

• Cascading Style Sheets, or CSS, is a style sheet language used on the Web.– CSS specifications are maintained by the World Wide Web Consortium

(W3C)

– Three versions of CSS exist: CSS1, CSS2, and CSS3.

Introducing Cascading Style Sheets

Page 4: Creating Css

• CSS1 - introduced styles for the following document features:– Fonts

– Text

– Color

– Backgrounds

– Block-level Elements

Cascading Style Sheets

Page 5: Creating Css

• CSS2 introduced styles for the following document features:– Positioning

– Visual Formatting

– Media Types

– Interfaces

Cascading Style Sheets

Page 6: Creating Css

• CSS3 (which is still in development) will introduce styles for the following document features:– User Interfaces– Accessibility– Columnar layout– International Features– Mobile Devices– Scalable Vector Graphics

Cascading Style Sheets

Page 7: Creating Css

• Three ways to apply a style to an HTML document:– Inline Styles

– Embedded Styles

– External Styles

Applying a Style Sheet

Page 8: Creating Css

• Inline styles are easy to use and interpret because they are applied directly to the elements they affect.

<element style=“style1: value1; style2: value2; style3: value3;…”>

• <h1 ALIGN="center" STYLE="background: #000080; font: 36pt/40pt courier; font-variant: small-caps; border: thick dashed blue">Welcome to my home page!</h1>

Using Inline Styles

Page 9: Creating Css

• <html>

• <head>

• <title> CSS </title>

• </head>

• <body STYLE="background: #000000; color: #80c0c0">

• <h1 ALIGN="center" STYLE="background: #000080; font: 36pt/40pt courier; 

• font-variant: small-caps; border: thick dashed blue"> Welcome to my home page!</h1>

• </body>

• </html>

Inline Styles Example

Page 10: Creating Css

• You can embed style definitions in a document head using the following form:

<style>

style declarations

</style>

Where style declarations are the declarations of the

different styles to be applied to the document.

Using Embedded Styles

Page 11: Creating Css

• An embedded style sheet is one in which the CSS code is written in the <head> section of an XHTML document

• On a blank line in the <head> section of an XHTML document, type:

<style type="text/css">

• Press the Enter key four times

• Type the end </style> tag

• Position the insertion point on the blank line between the start <style> and end </style> tags

• Type the CSS code

Creating an Embedded Style Sheet

Page 12: Creating Css

• The following code shows the syntax for an embedded style sheet:

<style type="text/css">

. . . CSS code is typed here . . .

</style>

Creating an Embedded Style Sheet

Page 13: Creating Css

Embedded Styles Example

Page 14: Creating Css

• Because an embedded style sheet only applies to the content of the start.htm file, you need to place a style declaration in an external style sheet to apply to the headings in the rest of the Web site

• An external style sheet is a text file that contains style declarations– It can be linked to any page in the site, allowing the same

style declaration to be applied to the entire site

Using an External Style Sheet

Page 15: Creating Css

• You can add style comments as you develop an external style sheet

• Use the link element to link a Web page to an external style sheet

• You can import the content of one style sheet into another

Using an External Style Sheet

Page 16: Creating Css

• A style is a consistent, recognizable pattern

• A CSS style is a collection of one or more rules

• A style sheet is a collection of styles

• A rule is the combination of a selector, a property, and a value

• The selector identifies the element to which you are applying a style.– Element, type, class, and id selectors

Understanding How Styles Are Written

Page 17: Creating Css

• In a text document, type the selector followed by a left brace, as in the following code, and then press the Enter key.

selector {

• Type the declarations (each indented by two or three spaces), separating a property from a value with a colon. Type a semicolon after each declaration, and then press the Enter key, as in the following code.

property: value;

Creating a CSS Style

Page 18: Creating Css

• Type a right brace on its own line (but not indented) below the declaration list. The following code shows the complete syntax for a rule:

selector {

property: value;

property: value;

}

Creating a CSS Style

Page 19: Creating Css

Understanding How Styles Are Written

Page 20: Creating Css

• The color property changes the foreground color of an element

• The background-color property changes the background color of an element

• You can define color in three ways:– By name

– By their RGB triplet

– By a hexadecimal value

Working with Color

Page 21: Creating Css

Working with Color

Page 22: Creating Css

• Grouped selectors are selectors with the same declarations grouped into a comma-separated list

Grouping Element Selectors

Page 23: Creating Css

• A descendant selector is a selector nested within another selector

Using Descendant Selectors

Page 24: Creating Css

Using Font Properties

Page 25: Creating Css

• The font-variant property can make text appear in small caps

Using Font Properties

Page 26: Creating Css

• The font-size property is used to change the font size

• You can express font size in:

– Centimeters

– Inches

– Millimeters

– Points

– Picas

– Pixels

– X-Height

– em

– Percentage

Using Font Properties

Page 27: Creating Css

• Em units and percents are examples of a relative value, a value that increases or decreases in size in relation to its parent element

• Point values are an absolute value, a fixed value that will not increase or decrease in size in relation to its parent element

Using Font Properties

Page 28: Creating Css

• The font-family property is used to change the typeface of text

• A font family is a set of fonts that have similar characteristics– Fonts you see depend on the platform

– Generic font

Using Font Properties

Page 29: Creating Css

Using Font Properties

Page 30: Creating Css

• Following the selector and the left-facing bracket, type font: on its own line, as shown in the following code:

h2 {

font:

• Type values for the font’s style, weight, variant, size, and family as applicable.

• Enter spaces between the values for the font properties.

• Enter commas between values for the font family.

Using the Font Shorthand Property

Page 31: Creating Css

• The following code shows the syntax for a completed rule:

h2 {

font: normal bold 1.4em Verdana, Helvetica, sans-serif;

}

Using the Font Shorthand Property

Page 32: Creating Css

• Use an id to distinguish something, like a paragraph, from the others in a document– For example, to identify a paragraph as “head”,

use the code:

<p id=“head”>… </p>

Using IDs and Classes

Page 33: Creating Css

• HTML and XHTML require each id be unique– therefore an id value can only be used once in a document

• You can mark a group of elements with a common identifier using the class attribute

<element class=“class”> … </element>

Classes

Page 34: Creating Css

Applying a style to a class

Page 35: Creating Css

Applying a style to a class and element

Page 36: Creating Css

• You can define the width of columns in a columnar layout using: width: value

• You can use CSS to set an element’s height using: height: value

• You can float a paragraph using: float: position

Sizing Elements and Floating an Element

Page 37: Creating Css

• The div element is a generic block-level element

<div>

content

</div>

Working with the div Element

Page 38: Creating Css

CSS background properties are used to define the background effects of an element.

CSS properties used for background effects:

• background-color

• background-image

• background-repeat

• background-attachment

• background-position

Working with Background

Page 39: Creating Css

Using Background Color

Page 40: Creating Css
Page 41: Creating Css

Using Background Image

Page 42: Creating Css

Using Background Image