CHAPTER 7 CSS – Style Sheet Cascading CSIT225 Internet Programming.

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

Cascading Style Sheets
HTML Overview - Cascading Style Sheets (CSS). Before We Begin Make a copy of one of your HTML file you have previously created Make a copy of one of your.
CHAPTER 7 STYLING CONTENT WITH CASCADING STYLE SHEETS.
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.
© 2004, Robert K. Moniot Chapter 6 CSS : Cascading Style Sheets.
1 Web Developer & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Chapter 8 Creating Style Sheets.
Chapter 6 Web Typography
Week 7 Web Typography. 2 Understanding Type Design Principles.
Introduction to Cascading Style Sheets (CSS) Module 2: HTML Basics LESSON 4.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic CSS: Cascading Style Sheets.
XP 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
Using Cascading Style Sheets CSS Structure. Goals Understand how contextual, class and ID selectors work Understand how contextual, class and ID selectors.
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
Using Cascading Style Sheets (CSS) Dept. of Computer Science and Computer Information CSCI N-100.
 Missing (or duplicate) semicolons can make the browser completely ignore the style rule.  You may add extra spaces between the properties/values to.
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,
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Cascading Style Sheets (CSS) Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
Using Cascading Style Sheets. Introduction to Styles and Properties  Cascading Style Sheets (CSS) are a standard set by the World Wide Web Consortium.
Chapter 4 Cascading Style Sheets Basics Key Concepts Copyright © 2013 Terry Ann Morris, Ed.D 1.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 3 Key Concepts 1 Copyright © Terry Felke-Morris.
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.
CSS Cascading Style Sheets By Garrett Garman. CSS Why use Style Sheets? Separates Appearance and Structure Modularity Quick and Easy changes Flexibility.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
INTRODUCTION TO HTML5 CSS Styles. Understanding Style Sheets  HTML5 enables you to define many different types of content on a web page, including headings,
Chapter 6 Web Typography. 2 Principles of Web Design Chapter 5 Objectives Understand principles for type design on a Web site Use the element Understand.
1 What is CSS?  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles are normally stored in Style Sheets  Styles.
ITCS373: Internet Technology Week 3: Introduction to CSS Dr. Faisal Al-Qaed.
Cascading Style Sheets Orientation Learning Web Design: Chapter 11.
CO1552 – Web Application Development Cascading Style Sheets.
INTRODUCTION TO CSS. OBJECTIVES: D EFINE WHAT CSS IS. K NOW THE HISTORY OF CSS. K NOW THE REASON WHY CSS IS USED. CSS SYNTAX. CSS ID AND CLASS.
Tutorial 5 Formatting with CSS. Objectives Session 5.1 – Evaluate why CSS styles are used – Determine where to write styles – Create an element selector.
Introduction to CSS. What is CSS?  Cascading Style Sheets  Used for styling HTML  Also important in javascript and jquery for selectors  External.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Tutorial 7.
Css. Definition Cascading style sheet (CSS)  It is a simple mechanism for adding style (e.g. fonts, colors, spacing) to Web documents.
Web Design and Development for Business Lecture 4 Cascading Style Sheet (CSS)
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Course created by Sarah Phillips BBCD Melbourne BAPDCOM Version 1 – April 2013.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKSTART GUIDE HTML and CSS 8th Edition Chapter 8: Working with Style Sheets.
XP Review 2 New Perspectives on JavaScript, Comprehensive1 Introducing Cascading Style Sheets Formatting Web Pages with CSS.
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,
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Microsoft Expression Web 3 – Illustrated Unit D: Structuring and Styling Text.
Web Technologies Beginning Cascading Style Sheets (CSS) 1Copyright © Texas Education Agency, All rights reserved.
How to… Cascading Style Sheets. How to Insert a Style Sheet When a browser reads a style sheet, it will format the document according to it. There are.
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.
Blended HTML and CSS Fundamentals 3 rd EDITION Tutorial 3 Introducing Cascading Style Sheets.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
What is CSS? A set of style rules that tell the web browser how to present a web page or document. – In earlier versions of HTML, style characteristics,
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Working with Cascading Style Sheets
An Introduction to Cascading Style Sheets
CSS: Cascading Style Sheets
Madam Hazwani binti Rahmat
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Introduction to Cascading Style Sheets (CSS)
What are Cascading Stylesheets (CSS)?
Made By : Lavish Chauhan & Abhay Verma
Presentation transcript:

CHAPTER 7 CSS – Style Sheet Cascading CSIT225 Internet Programming

UNIT 7 1 CSIT 225 – Internet Programming Why CSS Change the appearance of hundreds of Web pages by changing just one file Influence presentation without losing visitors (platform independence). Style sheets can make an author's life much easier.  While one could use for every horizontal rule, this becomes very cumbersome for the author.

UNIT 7 2 CSIT 225 – Internet Programming Why CSS With style sheets, one only needs to specify such presentational preferences once, and the style can be applied to an entire site. If the author decides that WIDTH="50%" would be better, then he or she only needs to change this preference in one place, rather than having to search through hundreds of pages to change the HTML. Style sheets also reduce download time when one file contains all the style information.

UNIT 7 3 CSIT 225 – Internet Programming Why CSS Properties such as color, background, margin, border, and many more can be applied to all elements. CSS separates content and presentation of the HTML. With this separation the Web no longer needs to drift away from the strong ideal of platform independence that provided the medium with its initial push of popularity. Authors can finally influence the presentation of documents without leaving pages unreadable to users.

UNIT 7 4 CSIT 225 – Internet Programming What is CSS A style sheet is made up of style rules that tell a browser how to present a document. Each rule is made up of a selector--usually an HTML element such as BODY, P, or EM--and the style to be applied to the selector. There are numerous properties that may be defined for an element. Each property takes a value, which together with the property describes how the selector should be presented.  Style rules are formed as follows:  selector { property: value } Multiple style declarations for a single selector may be separated by a semicolon:  selector { property1: value1; property2: value2 }

UNIT 7 5 CSIT 225 – Internet Programming What is CSS As an example, the following code segment defines the color and font-size properties for H1 and H2 elements: CSS Example H1 { font-size: x-large; color: red } H2 { font-size: large; color: blue } The above style sheet tells the browser to show level-one headings in an extra-large, red font, and to show level-two headings in a large, blue font

UNIT 7 6 CSIT 225 – Internet Programming Ways to link style sheets to HTML There are many ways to link style sheets to HTML, each carrying its own advantages and disadvantages.  Linking to an External Style Sheet  Embedding a Style Sheet  Importing a Style Sheet  Inlining Style New HTML elements and attributes have been introduced to allow easy incorporation of style sheets into HTML documents

UNIT 7 7 CSIT 225 – Internet Programming Linking to an External Style Sheet An external style sheet may be linked to an HTML document through HTML's LINK element.

UNIT 7 8 CSIT 225 – Internet Programming Linking to an External Style Sheet External style sheets should not contain any HTML tags like or. The style sheet should consist merely of style rules or statements. A file consisting solely of P { margin: 2em } could be used as an external style sheet.

UNIT 7 9 CSIT 225 – Internet Programming Linking to an External Style Sheet The tag also takes an optional MEDIA attribute, which specifies the medium or media to which the style sheet should be applied. Possible values are  screen (the default value), for presentation on non-paged computer screens;  print, for output to a printer;  projection, for projected presentations;  aural, for speech synthesizers;

UNIT 7 10 CSIT 225 – Internet Programming Linking to an External Style Sheet Possible values are (continues):  braille, for presentation on braille tactile feedback devices;  tty, for character cell displays (using a fixed-pitch font);  tv, for televisions;  all, for all output devices. Multiple media are specified through a comma-separated list or the value all.

UNIT 7 11 CSIT 225 – Internet Programming Linking to an External Style Sheet Possible values are (continues):  braille, for presentation on braille tactile feedback devices;  tty, for character cell displays (using a fixed-pitch font);  tv, for televisions;  all, for all output devices. Multiple media are specified through a comma-separated list or the value all.

UNIT 7 12 CSIT 225 – Internet Programming Linking to an External Style Sheet Advantages:  An external style sheet is ideal when the style is applied to numerous pages.  With an external style sheet, an author could change the look of an entire site by simply changing one file.  As well, most browsers will cache an external style sheet, thus avoiding a delay in page presentation once the style sheet is cached.

UNIT 7 13 CSIT 225 – Internet Programming Embedding a Style Sheet A style sheet may be embedded in a document with the STYLE element. <!– BODY { background: url(foo.gif) red; color: black } P EM { background: yellow; color: black }.note { margin-left: 5em; margin-right: 5em } -->

UNIT 7 14 CSIT 225 – Internet Programming Embedding a Style Sheet The STYLE element is placed in the document HEAD. The required TYPE attribute is used to specify a media type, as is its function with the LINK element. Similarly, the TITLE and MEDIA attributes may also be specified with STYLE. An embedded style sheet should be used when a single document has a unique style. If the same style sheet is used in multiple documents, then an external style sheet would be more appropriate.

UNIT 7 15 CSIT 225 – Internet Programming Embedding a Style Sheet Older browsers, unaware of the STYLE element, would normally show its contents as if they were part of the BODY, thus making the style sheet visible to the user. To prevent this, the contents of the STYLE element are contained within an SGML comment ( ), as in the preceding example.

UNIT 7 16 CSIT 225 – Internet Programming Importing a Style Sheet A style sheet may be imported with statement. This statement may be used in a CSS file or inside the STYLE element: url(/stylesheets/punk.css); DT { background: yellow; color: black } -->

UNIT 7 17 CSIT 225 – Internet Programming Importing a Style Sheet Note that other CSS rules may still be included in the STYLE element, but that statements must occur at the start of the style sheet. Any rules specified in the style sheet itself override conflicting rules in the imported style sheets. For example, even if one of the imported style sheets contained DT { background: aqua }, definition terms would still have a yellow background.

UNIT 7 18 CSIT 225 – Internet Programming Importing a Style Sheet The order in which the style sheets are imported is important in determining how they cascade. In the previous example, if the style.css imported style sheet specified that STRONG elements be shown in red and the punk.css style sheet specified that STRONG elements be shown in yellow. The latter rule would win out, and STRONG elements would be in yellow.

UNIT 7 19 CSIT 225 – Internet Programming Importing a Style Sheet Imported style sheets are useful for purposes of modularity. There may be a simple.css style sheet that gives rules for common elements such as BODY, P, H1, and H2. In addition, there may be an extra.css style sheet that gives rules for less common elements such as CODE, BLOCKQUOTE, and DFN. A tables.css style sheet may be used to define rules for table elements. These three style sheets could be included in HTML documents, as needed, with statement. The three style sheets could also be combined via the LINK element.

UNIT 7 20 CSIT 225 – Internet Programming Inlining Style Style may be inlined using the STYLE attribute. The STYLE attribute may be applied to any BODY element (including BODY itself) except for BASEFONT, PARAM, and SCRIPT.BODY BASEFONTPARAMSCRIPT The attribute takes as its value any number of CSS declarations, where each declaration is separated by a semicolon. An example follows: This paragraph is styled in red with the Times New Roman font, if available.

UNIT 7 21 CSIT 225 – Internet Programming Inlining Style Inlining style is far more inflexible than the other methods. To use inline style, one must declare a single style sheet language for the entire document using the Content-Style-Type HTTP header extension. With inlined CSS, an author must send text/css as the Content-Style-Type HTTP header or include the following tag in the HEAD:

UNIT 7 22 CSIT 225 – Internet Programming Inlining Style Inlining style loses many of the advantages of style sheets by mixing content with presentation. As well, inlined styles implicitly apply to all media, since there is no mechanism for specifying the intended medium for an inlined style. This method should be used sparingly, such as when a style is to be applied on all media to a single occurrence of an element.

UNIT 7 23 CSIT 225 – Internet Programming The CLASS Attribute The CLASS attribute is used to specify the style class to which the element belongs. For example, the style sheet may have created the punk and warning classes:.punk { color: lime; background: #ff80c0 } P.warning { font-weight: bolder; color: red; background: white } These classes could be referenced in HTML with the CLASS attribute: Proprietary Extensions Many proprietary extensions can have negative side-effects, both on supporting and non-supporting browsers...

UNIT 7 24 CSIT 225 – Internet Programming The CLASS Attribute In this example, the punk class may be applied to any BODY element since it does not have an HTML element associated with it in the style sheet. Using the example's style sheet, the warning class may only be applied to the P element. A good practice is to name classes according to their function rather than their appearance. The warning class in the previous example could have been named red, but this name would become meaningless if the author decided to change the style of the class to a different color, or if the author wished to define an aural style for those using speech synthesizers.

UNIT 7 25 CSIT 225 – Internet Programming The CLASS Attribute Classes can be a very effective method of applying different styles to structurally identical sections of an HTML document. For example, this page uses classes to give a different style to CSS code and HTML code.

UNIT 7 26 CSIT 225 – Internet Programming The ID Attribute The ID attribute is used to define a unique style for an element. A CSS rule such as #wdg97 { font-size: larger } may be applied in HTML through the ID attribute: Welcome to the Web Design Group! Each ID attribute must have a unique value over the document. The value must be an initial letter followed by letters, digits, or hyphens. The letters are restricted to A-Z and a-z.

UNIT 7 27 CSIT 225 – Internet Programming The ID Attribute The use of ID is appropriate when a style only needs to be applied once in any document. ID contrasts with the STYLE attribute in that the former allows medium-specific styles and can also be applied to multiple documents (though only once in each document).

UNIT 7 28 CSIT 225 – Internet Programming The SPAN Element The SPAN element was introduced into HTML to allow authors to give style that could not be attached to a structural HTML element. SPAN may be used as a selector in a style sheet, and it also accepts the STYLE, CLASS, and ID attributes. Some examples of SPAN follow: Example of SPAN <!–.firstwords { font-variant: small-caps } --> The first few words of a paragraph could be in small-caps. Style may also be inlined, such as to change the style of a word like Arial.

UNIT 7 29 CSIT 225 – Internet Programming The DIV Element The DIV element is similar to the SPAN element in function, with the main difference being that DIV (short for "division") is a block-level element. DIV may contain paragraphs, headings, tables, and even other divisions. This makes DIV ideal for marking different classes of containers, such as a chapter, abstract, or note. For example: Divisions The DIV element is defined in HTML 3.2, but only the ALIGN attribute is permitted in HTML 3.2. HTML 4.0 adds the CLASS, STYLE, and ID attributes, among others. Since DIV may contain other block-level containers, it is useful for marking large sections of a document, such as this note. The closing tag is required.

UNIT 7 30 CSIT 225 – Internet Programming CSS Structure and Rules Rules  Selectors  The selector is simply the element that is linked to a particular style.  For example, the selector in P { text-indent: 3em } is P.  Class Selectors A simple selector can have different classes, thus allowing the same element to have different styles. For example, an author may wish to display code in a different color depending on its language: code.html { color: # } code.css { color: #4b0082 } The above example has created two classes, css and html for use with HTML's CODE element.

UNIT 7 31 CSIT 225 – Internet Programming CSS Structure and Rules  Class Selectors Only one class is allowed per selector. For example, code.html.proprietary is invalid.  Classes may also be declared without an associated element :.note { font-size: small }  In this case, the note class may be used with any element.  A good practice is to name classes according to their function rather than their appearance.  The note class in the above example could have been named small, but this name would become meaningless if the author decided to change the style of the class so that it no longer had a small font size.

UNIT 7 32 CSIT 225 – Internet Programming CSS Structure and Rules  ID Selectors ID selectors are individually assigned for the purpose of defining on a per-element basis. This selector type should only be used sparingly due to its inherent limitations. An ID selector is assigned by using the indicator "#" to precede a name. For example, an ID selector could be assigned as such: #svp94O { text-indent: 3em } This would be referenced in HTML by the ID attribute: Text indented 3em

UNIT 7 33 CSIT 225 – Internet Programming CSS Structure and Rules  Contextual Selectors Contextual selectors are merely strings of two or more simple selectors separated by white space. These selectors can be assigned normal properties and, due to the rules of cascading order, they will take precedence over simple selectors. For example, the contextual selector in P EM { background: yellow } is P EM. This rule says that emphasized text within a paragraph should have a yellow background. Emphasized text in a heading would be unaffected.

UNIT 7 34 CSIT 225 – Internet Programming CSS Structure and Rules Properties  A property is assigned to a selector in order to manipulate its style.  Examples of properties include color, margin, and font. Values  The declaration value is an assignment that a property receives.  For example, the property color could receive the value red. Grouping  In order to decrease repetitious statements within style sheets, grouping of selectors and declarations is allowed.  For example, all of the headings in a document could be given identical declarations through a grouping: H1, H2, H3, H4, H5, H6 { color: red; font-family: sans-serif }

UNIT 7 35 CSIT 225 – Internet Programming CSS Structure and Rules Inheritance  Virtually all selectors which are nested within selectors will inherit the property values assigned to the outer selector unless otherwise modified.  For example, a color defined for the BODY will also be applied to text in a paragraph. Comments  Comments are denoted within style sheets with the same conventions that are used in C programming. A sample CSS1 comment would be in the format: /* COMMENTS CANNOT BE NESTED */

UNIT 7 36 CSIT 225 – Internet Programming Cascading Order When multiple style sheets are used, the style sheets may fight over control of a particular selector. In these situations, there must be rules as to which style sheet's rule will win out. 1.! important Rules can be designated as important by specifying ! important. A style that is designated as important will win out over contradictory styles of otherwise equal weight. Likewise, since both author and reader may specify important rules, the author's rule will override the reader's in cases of importance. A sample use of the ! important statement: BODY { background: url(bar.gif) white; background-repeat: repeat-x ! important }

UNIT 7 37 CSIT 225 – Internet Programming Cascading Order 2.Origin of Rules (Author's vs. Reader's). Both authors and readers have the ability to specify style sheets. When rules between the two conflict, the author's rules will win out over reader's rules of otherwise equal weight. Both author's and reader's style sheets override the browser's built-in style sheets.  Authors should be wary of using ! important rules since they will override any of the user's ! important rules.  Any ! important rules will override normal rules, so authors are advised to use normal rules almost exclusively to ensure that users with special style needs are able to read the page.