CSS (Cascading Style Sheet)

Slides:



Advertisements
Similar presentations
Table, List, Blocks, Inline Style
Advertisements

CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Cascading Style Sheets Basics. Why use Cascading Style Sheets? Allows you to set up a series of rules for all pages in a site. The series may be changed.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
© 2010, Robert K. Moniot Chapter 5 CSS : Cascading Style Sheets 1.
Week 7 Web Typography. 2 Understanding Type Design Principles.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 3 Style Sheets: CSS WEB.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 3 Style Sheets: CSS WEB.
SM5312 week 6: basic CSS syntax1 An Introduction to Cascading Style Sheets Basic CSS Syntax Nick Foxall.
CSS: Cascading Style Sheets. What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
Cascading Style Sheet (CSS) Instructor: Dr. Fang (Daisy) Tang
3.1 Cascading Style Sheets. Motto Fashions fade, style is eternal. —Yves Saint Laurent.
CSS: Cascading Style Sheets. 2 History HTML tags were originally designed to define the content of a document. The layout of the document was supposed.
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
Principles of Web Design 6 th Edition Chapter 4 – Cascading Style Sheets.
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Review: Three parts to a webpage: - Content - Structure  XHTML - Presentation  CSS In this chapter we will focus on introducing and examining the mechanics.
Chapter 7 Web Typography Principles of Web Design, 4 th Edition.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
Cascading Style Sheet (CSS)
New Perspectives on XML, 2nd Edition Tutorial 5 1 TUTORIAL 5 WORKING WITH CASCADING STYLE SHEETS.
XP New Perspectives on XML Tutorial 5 1 TUTORIAL 5 CSS Tutorial – Carey ISBN
Today’s objectives  Complete web page  Using xhtml & CSS  Adding CSS to documents Embed url(File);  CSS.
Cascading Style Sheets. Defines the presentation of one or more web pages Similar to a template Can control the appearance of an entire web site giving.
Today’s objectives  Presentational | Inline | Block | Validate  CSS | Rules | Declarations.
WDV 101 Intro to Website Development
CSS: Cascading Style Sheets. 2 What are Style Sheets A style sheet is a mechanism that allows to specify how HTML (/XHTML/XML) pages should look The style.
Tutorial #4 Formatting Text and Links. Tutorial #3 Review - CSS CSS format Selector { property1: value1; /* Comments */ } Embedded, In-Line, and External.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
Tutorial 5 Formatting with CSS. Objectives Session 5.1 – Evaluate why CSS styles are used – Determine where to write styles – Create an element selector.
Tutorial #3 Cascading Style Sheets. Tutorial #2 Review - Anchors Links to Site DMACC Internal Links Go to Top Mail To me Local.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
MySQL and PHP Review CSS. Cascading Style Sheet (CSS) Style sheets are files or forms that describe the layout and appearance of a document. Cascading.
CSS Tutorial 1 Introduction Syntax How to use style specifications. Styles.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
Cascading Style Sheets Robin Burke ECT 270. Outline Midterm The Layout Debate CSS properties Fonts Alignment Color CSS selection selectors pseudo-classes.
ECA225 Applied Interactive Programming Cascading Style Sheets, pt 1 ECA 225 Applied Online Programming.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
Cascading Style Sheets Eugenia Fernandez IUPUI. CSS Purpose CSS allow you to specify the style in which your XML elements are displayed. CSS were originally.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
1 Web Development CSS (Cascading Style Sheet). 2 1.Setting rules for multiple elements To decrease the amount of typing for setting rules for multiple.
1 Working with Cascading Style Sheet (CSS). 2 Cascading Style Sheets (CSS)  a style defines the appearance of a document element. o E.g., font size,
Developing Web Applications with HTML and CSS “Selectors and Properties”
Relative, absolute, and Floating Positioning, Cascading Style Sheet, and Inheritance.
CSS: Cascading Style Sheets Part II. Style Syntax.
1 Lecture 7 Style Sheets: CSS. 2 Motivation HTML markup can be used to represent –Semantics: h1 means that an element is a top-level heading –Presentation:
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
ECA 228 Internet/Intranet Design I Cascading Style Sheets.
Chapter 11 & 12 CSS Style Sheets: Intro. Why CSS? Separate presentation from content – more accessible Less work – can change appearance of whole site.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Internet & World Wide Web How to Program, 5/e 1. 2.
Cascading Style Sheets
Chapter 3 Style Sheets: CSS
Using Cascading Style Sheets Module B: CSS Structure
Cascading Style Sheets
IS333: MULTI-TIER APPLICATION DEVELOPMENT
CSS Style Sheets: Intro
Cascading Style Sheets Color and Font Properties
Cascading Style Sheets
Cascading Style Sheets
Cascading Style Sheets™ (CSS)
Presentation transcript:

CSS (Cascading Style Sheet) English for ICT

HTML vs. CSS HTML can be used to indicate both semantic of document and its presentation It is advisable to separate HTML for semantic and use CSS to determine how the document should be presented CSS (Cascading Style Sheet) is used to work with HTML and XML CSS provides a variety of features for document presentation

Parts of a Single ruleset-type Style Rule property names font-size : x-large background-color : yellow p { } declarations selector string declaration block

Specifying Style Rules The syntax for specifying style properties is: For multiple properties: Selector { property: value} Selector { property1: value1; property2: value2; property3: value3; ………. …… propertyN: valueN; }

How a Style can be used? External (Imported) Embedded Inline CSS is a separate file from HTML Embedded Style rules are defined inside HTML file Inline Style is applied within HTML tags Actually, it is an attribute of HTML tags

Inline Style <body style="background-color: lime;"> <p id="test" style="font-size:x-large; background-color: yellow;"> Hello World! </p> </body>

Embeded Style <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <style type="text/css"> body { background-color: lime; } p { font-size: x-large; background-color: yellow; } </style> </head> <body> <p id="test"> Hello World! </p> </body> </html>

External Style style2.css style1.css body { background-color: lime; } p { font-size: x-large; background-color: yellow; } style1.css body { background-color: yellow; } p { font-size: x-large; background-color: blue; } style2.css <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="style1.css" rel="stylesheet" type="text/css" title="Style 1" /> <link href="style2.css" rel="alternate stylesheet" type="text/css" title="Style 2" /> </head> <body> <p id="test"> Hello World! </p>

External Style (contd)

Applying Style Sheet according to Media Type title attribute are not needed These style sheets cannot be selected by users They will apply regardless of user actions Such style sheets are called persistent They can be recognized by their lack of a title attribute <title>Title of document</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="style1.css" rel="stylesheet" type="text/css" media="screen, tv, projection" /> <link href="style2.css" rel="stylesheet" type="text/css" media="handheld, print" /> </head>

Possible Values for media Attribute (HTML 4.0 Standard) Media Type all All types (default) aural Speech synthesizer braille Tactile device generating braille characters handheld Handheld device, such as a cell phone or PDA print Printer projector Projector, such as one used to display a large monitor image on a screen screen Computer monitor tty Fixed-width character output device tv Television (monitor with low resolution and little or no scrolling)

Benefits of Using Style Sheet It is easy to give all of elements on a page a consistent appearance If, at a later time, we wish to change an attribute value, we need only make change in on style sheet. If we use a single style sheet for all of the pages at a site, all of the site pages will have a consistent style, and one that can be changed with little work

Selector Types Type selector Universal selector ID selector Class selector Pseudo-Class selector Descendant selector

style_demo.css /* Headers have dark background */ h1, h2, h3, h4, h5, h6 { background-color : purple } /* All elements bold */ * { font-weight : bold } /* Elements with certain id's have light background */ #p1, #p3 { background-color : aqua } /* Elements in certain classes are italic, large font, or both */ #p4, .takenote { font-style : italic } span.spacial { font-size : x-large } /* Hyperlink ('a' element) styles */ a:link { color : black } a:visited { color : yellow } a:hover { color : green } a:active { color : red } /* Descendant selectors */ ul span { font-variant : small-caps } ul ol li { letter-spacing : 1em } style_demo.css

Type Selector Simplest form is to use the name of single element type, such as: body or p, etc. A rule can apply to multiple elements by separating them with comma such as: h1, h2, h3, h4 This specifies that purple is applied to all headers’ background color h1, h2, h3, h4, h5, h6 { background-color : purple }

Universal Selector The universal selector is denoted by an asterisk (*) Universal selector represents ever possible element type This specifies a value of bold for the font-weight property of every element in the document * { font-weight : bold }

ID Selector Every element in an XHTML has an associated id attribute If a value is assigned to id attribute, then no other element’s id can be the same name ID selector can be used by preceding a selector name with a number sign (#)

ID Selector Example #p1, #p3 { background-color : aqua } The element with id p1 or p3 will be rendered with its background color of aqua <p id=“p3”> blah blah blah …. </p>

Class Selector Another HTML attribute frequently used with style sheet is class Class selector can be represented by preceding the selector name with a period (.) Class selector is different from ID selector in that it allows multiple use of the style as oppose to ID select, which applies to only a single element

Class Selector Example #p4, .takenote { font-style : italic } Element needing to have this effect can add “takenote” to its class attribute as follow: This means class “special” can be used with span element only <span class=“takenote”> …….</span> or <span class=“takenote special cool”> …… </span> span.special { font-size : x-large } Note: *.takenote and .takenote are equivalent.

Pseudo-Class Selector Associated a Elements a:visited Any element with href corresponding to a URL that has been visited recently a:link Any element that does not belong to the a:visited pseudo-class a:active An element that is in the process of being selected; for example, the mouse has been clicked on the element but not released a:hover An element over which the mouse cursor is located but that does not belong to the a:active pseudo-class

Descendant Selector A selector that hold only within the content of certain element types is known as a descendant selector Text within a span that is part of ul should be displayed using a small-cap font form The selector applies to any span within content of any element belonging to class special ul span { font-variant : small-caps } .special span { letter-spacing : 1em }

At-Rules The at-rule that is widely used is @import This is used to input one style sheet file into another one This file reads in rules from the file “general-rules.css” before continuing with other rule in this style sheet url() represents a URL, which can be absolute or relative @import url(‘general-rules.css’); h1, h2 { background-color : aqua }

Style Sheet Rules Cascading of style sheet rules (Style Rule Cascading) Element inheritance of style properties (Style Rule Inheritance)

Style Rule Cascading * { font-weight : bold } #p1, #p3 { background-color : aqua } Both rules apply to element with id attribute value p3 If multiple rules with same properties apply to an element, the all of declarations are applied to the element What happens if the below rule is added: Which rule would apply to the font-weight property of p3 ? #p3 { font-weight : normal }

Style Rule Cascading Origin of a declaration: (who wrote the declaration?) Author: declaration is part of an external or embedded style sheet or is part of the value specified for the style attribute of an element User agent: A browser or other user agent may define default style property values for HTML elements User: Most browsers allow users to provide a style sheet or to indicate style preferences that are treated as style rules

Style Rule Cascading Every author and user style declaration has one of two weight values: normal and important A declaration has important weight if it ends with “!important” This will give important weight to font-size property while the text-indent property will have normal weight p { text-indent: 3cm ; font-size : larger !important }

Style Rule Cascading The priorities from height to low: Important declaration with user origin Important declaration with author origin Normal declaration with author origin Normal declaration with user origin Any declaration with user agent origin The reason that user declaration has higher priority is accessibility.

Style Rule Cascading To sort the tied declarations according to their specificity If a declaration is part of the style attribute of the element, then it is highest specificity If a declaration is part of a ruleset, then its specificity is determined by the selector(s) for the ruleset.

Style Rule Cascading Highest to lowest specificity are: ID selectors Class and pseudo-class selectors Descendant and type selector (the more element type names, the more specific) Universal selectors

Style Rule Cascading Even after this sorting process, two or more declarations may have equally high weight-origin and specificity The final step is then applied: If there is a declaration in the style attribute for element, then it is used Otherwise, all of style sheet rules are listed in a top-to-bottom reading of the document, with external and imported style sheets inserted at the point of the link element or @import rule

Style Rule Cascading Then style rulesets are effectively in the order @import url(“imp2.css”); p { color : green } imp1.css <title>StyleRuleOrder.html</title> <style type="text/css"> p { color : red } </style> <link rel="stylesheet“ type="text/css“ href="imp1.css" /> p { color : yellow } p { color : blue } imp2.css Then style rulesets are effectively in the order p { color : red } p { color : blue } p { color : green } p { color : yellow } <p>Hello world!</p> would then display in yellow.

Style Rule Cascading Summary Alternate style sheets 1. Select style sheet and insert rules for HTML attributes 2. Prioritize declarations by origin and weight 3. Break ties based on specificity (style attribute or most specific selector) 4. Break ties based on position within style sheet (last occurring wins

Style Rule Inheritance Cascading is based on structure of style sheets Inheritance is based on the tree structure of the document itself. An element inherits a value for one of its properties by checking if its parent element in documents has a value for that property, if so, inheriting the parent’s value However, parent may inherit its property value from its parent, and so on.

HTML demonstrating Style Inheritance <head> <title>style_inherit.html</title> <style type="text/css"> body { font-weight : bold } li { font-style : italic } p { font-size : larger } span { font-weight : normal } </style> </head> <body> <ul> <li> List item outside and <span>inside</span> a span. <p> Embedded paragraph outside and <span>inside</span> a span. </p> </li> </ul> </body>

Rendering Style Inheritance

CSS Generic Font Families Font Family Description serif A serif is a short, decorative line at the end of a stroke of a letter. There are 3 serifs at the top of the W. Most glyphs in a serif font family will have serifs, and such a family is typically proportionately spaced (different glyphs occupy different widths). sans-serif Usually proportionately spaced, but glyphs lack serifs, so they don’t look as fancy as serif fonts. cursive Looks more like cursive handwriting than like printing. fantasy Glyphs are still recognizable as characters, but are nontraditional. monospace All glyphs have the same width. Since monospace fonts are often used in editors when programming, these font families are frequently used to display program code or other computer data.

CSS Length Unit Identifiers Meaning in Inch cm Centimeter mm Millimeter pt Point: 1/72 inch pc Pica: 12 points px Pixel: typically 1/96 inch em Em: reference font size ex Ex: roughly the height of the lowercase “x” character in the reference font

Font Style Properties Property Possible Values font-style normal (initial value), italic, or oblique font-weight bold or normal (initial value) font-variant small-caps, which displays lowercase characters using uppercase glyphs (small uppercase glyphs if possible), or normal (initial value)