Cascading Style Sheets (CSS) Mrs.C.Santhiya Assistant Professor TCE,Madurai.
Motivation  Consistent look.  Multiple platforms  Division of labor  User control
Style Sheet Languages Cascading Style Sheets (CSS) Extensible Style sheet Language (XSL)  Often used to transform one XML document to another form, but can also add style.
CSS Introduction A styled HTML document produced by the style sheet style1.css:
CSS Introduction link element associates style sheet with doc.
CSS Introduction type attribute specifies style language used
CSS Introduction href attribute provides style sheet URL
CSS Introduction title attribute provides style sheet name
CSS Introduction Alternative, user selectable style sheets can be specified
CSS Introduction
CSS Introduction A styled HTML document produced by the style sheet style2.css:
CSS Introduction Single document can be displayed on multiple media platforms by tailoring style sheets: This document will be printed differently than it is displayed.
CSS Syntax Parts of a style rule (or statement)
CSS Syntax: Selector Strings Single element type: Multiple element types: All element types: Specific elements by id:
CSS Syntax: Selector Strings Elements belonging to a style class:  Referencing a style class in HTML: Elements of a certain type and class: class selector: begins with a period .
CSS Syntax: Selector Strings Elements belonging to a style class:  Referencing a style class in HTML: Elements of a certain type and class: this span belongs to three style classes
CSS Syntax: Selector Strings Elements belonging to a style class:  Referencing a style class in HTML: Elements of a certain type and class: this rule applies only to span’s belonging to class special
CSS Syntax: Selector Strings Source anchor elements: Element types that are descendents: pseudo-classes
CSS Syntax: Selector Strings Source anchor elements: Element types that are descendants: rule applies to li element that is
CSS Syntax: Selector Strings Source anchor elements: Element types that are descendants: rule applies to li element that is part of the content of an ol element
CSS Syntax: Selector Strings Source anchor elements: Element types that are descendants: rule applies to li element that is part of the content of an ol element that is part of the content of a ul element
Style Sheets and HTML
CSS Rule Cascade Specificity: 1.style attribute 2.rule with selector: 1. ID 2. class/pseudo-class 3. descendant/element type 4. universal 3.HTML attribute
CSS Inheritance
CSS Inheritance Property values:  Specified: value contained in declaration  Absolute: value can be determined without reference to context (e.g., 2cm)  Relative: value depends on context (e.g., larger)  Computed (e.g., larger might be 1.2 x parent font size)  Actual: value actually used by browser (e.g., computed value might be rounded)
CSS Font Properties Computed value of font-size property
CSS Font Properties font-size:  Percentage (of parent font-size)  Absolute size keyword: xx-small, x-small, small, medium (initial value), large, x-large, xx-large  User agent specific; should differ by ~ 20%  Relative size keyword: smaller, larger  Relative to parent element’s font
CSS Font Properties Text is rendered using line boxes Height of line box given by line-height  Initial value: normal (i.e., cell height; relationship with em height is font-specific)  Other values (following are equivalent):
CSS Font Properties
CSS Font Properties font shortcut property: Initial values used if no value specified in font property list (that is, potentially reset)
CSS Text Formatting
CSS Text Color
CSS Text Color
CSS Box Model Every rendered element occupies a box: (or inner edge) (or outer edge)
CSS Box Model
CSS Box Model
CSS Box Model
CSS Box Model
Backgrounds <body style="background-image:url('CucumberFlowerPot.png')">
Normal Flow Layout Block elements only
Normal Flow Layout html body div d1 div d2 div d3 div d4 Top edges of block boxes are in document order
Normal Flow Layout Centering can be achieved by setting both margins to auto
Beyond Normal Flow CSS allows for boxes to be positioned outside the normal flow:  Relative positioning span’s shifted backwards relative to normal flow
Beyond Normal Flow CSS allows for boxes to be positioned outside the normal flow:  Float positioning span taken out of normal flow and “floated” to the left of its line box
Beyond Normal Flow CSS allows for boxes to be positioned outside the normal flow:  Absolute positioning span’s removed from normal flow and positioned relative to another box
Beyond Normal Flow Properties used to specify positioning:  position: static (initial value), relative, or absolute  Element is positioned if this property not static  Properties left, right, top, bottom apply to positioned elements  Primary values are auto (initial value) or CSS length  float: none, left, or right  Applies to elements with static and relative positioning only
Beyond Normal Flow Float positioning  Specify value for float property
Beyond Normal Flow Absolute positioning  Specify location for corner of box relative to positioned containing block margin area padding area containing block This second paragraph has a note. p elements are positioned (but don’t move!)
Beyond Normal Flow Absolute positioning  Specify location for edges of box relative to positioned containing block
Beyond Normal Flow Absolute positioning 10em padding top edge padding left edge
Beyond Normal Flow Absolute positioning 8em

Css lecture notes